尚硅谷C语言零基础教程(宋红康c语言程序设计精讲,含C语言考研真题)
2023-10-24 17:56 作者:Kazuma_124 | 我要投稿

int main(){
return 0;//返回0表示程序正常执行,非零表示非正常执行
}
%n是输出控制符,将printf函数已经输出的字符数存储到对应的参数中;
int n;
printf("Hello,world!%n\n",&n);
printf("%d",n);//12
---
099.register、extern、const修饰变量 P99 - 12:14
void test1() {
const int num = 10;
//num = 20;报错
}
void test2() {
int num1 = 10;
const int* ptr = &num1;
//*ptr = 20;报错,ptr为一个指向常量的指针,它地址指向的值不能修改
int num2 = 20;
ptr = &num2;
num1 = 20;//num1不是常量,可以被修改,但ptr是一个指向常量的指针,不能利用ptr修改它指向的变量
}
void test3() {
int num1 = 10;
int* const ptr = &num1;
int num2 = 20;
//ptr = &num2;报错,ptr为常量指针,其存储的地址不能修改
const int(*ptr2) = &num1;
//ptr = &num2;仍报错
//const优先级比*高,所以单纯的const int *标识符;会优先判断为int型常量,再判断该变量为指针变量
}