1.程序入口
int main() {
printf("Hello, World!\n");
return 0;
}
2.函数
void change(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int a = 10, b = 20;
change(&a, &b);
printf("a=%d,b=%d", a, b);
return 0;
}
2.基本数据类型占位输出
// 基本数据类型
int main() {
int i = 100;
double d = 200;
float f = 200;
long l = 100;
short s = 100;
char c = 'd';
// 字符串
char * str = "Hello";
// 不是随便打印的,需要占位
printf("i的值是:%d\n", i); // d == 整形
printf("d的值是:%lf\n", d); // lf == long float
printf("f的值是:%f\n", f); // f == float
printf("l的值是:%d\n", l); // d == 整形
printf("s的值是:%d\n", s); // s == short
printf("c的值是:%c\n", c); // c == char
printf("字符串:%s\n", str); // s == String
// getchar();
}
3.基本类型占用的字节数
int main() {
int i = 100;//4个字节
double d = 200;//8个字节
float f = 200;//4个字节
long l = 100;//4个字节
long long ll = 1010;//8个字节
short s = 100;//2个字节
char c = 'd';//1个字节
// 不是随便打印的,需要占位
printf("int占用的字节数是:%llu\n", sizeof(int));
printf("double占用的字节数是:%llu\n", sizeof(double));
printf("float占用的字节数是:%llu\n", sizeof(float));
printf("long占用的字节数是:%llu\n", sizeof(long));
printf("longlong占用的字节数是:%llu\n", sizeof(long long));
printf("short占用的字节数是:%llu\n", sizeof(short));
printf("char占用的字节数是:%llu\n", sizeof(char));
}
4.初次感受,万物皆地址
int main() {
//变量的地址就是指针
//指针的地址还是一个指针(二级指针)
int i = 100;
int *p = &i;
printf("i的值是:%d\n", i);
printf("i的地址是:%p\n", &i);
printf("p的值是:%p\n", p);
printf("p的地址是:%p\n", &p);
}
网友评论