基本數(shù)據(jù)類型
字符型
char c = 'a';
整數(shù)型
int a = 7, b = 8, c;
c = a + b;
c = a - b;
數(shù)組
int array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8 ,9};
char name[10] = "Underwood";
array[0] = 10;
name[0] = 'u';
結(jié)構(gòu)體
struct A {
int number;
char name[10];
};
struct A s;
s.number = 10;
s.name[0] = 'a';
指針
int a = 0;
int *pa = &a;
*pa = 5;
char name[10];
char *pc = name;
*pc = 'a';
pc += 1;
*pc = 'b';
struct A {
int number;
char name[10];
};
struct A s;
struct A *ps = &s;
ps->number = 10;
ps->name[0] = 'a';
流程控制
分支語句
int age = 18;
if (age >=18)
printf("An adult\n");
else if (age >= 3)
printf("A child\n");
else
printf("A baby");
循環(huán)語句
int i, sum = 0;
for (i = 0; i < 10; i++)
sum += I;
int i = 0, sum = 0;
while (i < 10) {
sum += i;
i++;
}
函數(shù)
void check_age(int age) {
if (age >=18)
printf("An adult\n");
else if (age >= 3)
printf("A child\n");
else
printf("A baby");
}
check_age(18);
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者