#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);
}
c语言练习
最新推荐文章于 2024-10-15 22:45:07 发布