c语言练习

#include <stdio.h>
#include <float.h>
#include <stdlib.h>
#include <string.h>
/*函数声明*/
void func1(void);

static int count=10;

/*枚举*/
enum DAY{
	MON=1,
	TUE,
	WED,
	THU,
	FRI,
	SAT,
	SUN
} day;


//回调函数
void populate_array(int *array,size_t arraySize,int (*getNextValue)(void)){
for(size_t i=0;i<arraySize;i++){
	array[i]=getNextValue();
}	
}

//获取随机值
int getNextRandomValue(void){
	return rand();
}

/*
union Data{
	int i;
	float f;
	char str[20];
}
*/
int main(){
	
/*标准输入输出*/	
/*
int c;
printf("please input a value");
c=getchar();
printf("\n you input:");
putchar(c);
printf("\n");*/
/*char缓冲输入输出*/
printf("------------------------");

char str[100];
printf("please imput a value :\n");
gets(str);
printf("\n you input a value is :");
puts(str);	
	
/*	
union Data data;
data.i=10;
printf("data.i :%d\n",data.i);
data.f=220.5;
printf("data.f :%d\n",data.f);
strcpy(data.str,"c programming");
printf("data.str :%s \n",data.str);	
*/

/*this is my fisrt c program*/
printf("hello,world!!\n");
printf("int %lu \n",sizeof(int));
/*this is float demo*/
printf("float %lu\n",sizeof(float));
printf("float max value %E\n",FLT_MAX);
printf("float min value %E\n",FLT_MIN);
printf("float %d\n",FLT_DIG);
while(count--){
	func1();
}
/*数组*/
int n[10];
int i,j;
for(i = 0;i<10;i++){
	n[i]=i+100;
}

for(j=0;j<10;j++){
 printf("element[%d]=%d\n",j,n[j]);
}
/*遍历枚举元素*/
for(day=MON;day<=SUN;day++){
printf("emun element is %d\n",day);
}

/*指针*/
int *ptr = NULL;
printf("ptr address is %p\n",ptr);

/*指针回调函数*/
int myarray[10];
populate_array(myarray,10,getNextRandomValue);
for(int i=0;i<10;i++){
	printf("callbcak function %d \n",myarray[i]);
}
/*位域*/
struct bs{
	int a8:1;
	int b8:3;
	int c8:4;
}bit,*pbit;
bit.a8=1;
bit.b8=7;
bit.c8=4;
printf("%d %d %d \n",bit.a8,bit.b8,bit.c8);
pbit=&bit;
pbit->a8=0;
pbit->b8=0;
pbit->c8=0;
printf("%d ,%d,%d\n",pbit->a8,pbit->b8,pbit->c8);
return 0;
}

void func1(void){
	static int thingy=5;
	thingy++;
	printf("thingy is %d ,count is %d \n",thingy,count);
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

科学熊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值