尚硅谷C語(yǔ)言零基礎(chǔ)教程(宋紅康c語(yǔ)言程序設(shè)計(jì)精講,含C語(yǔ)言考研真題)
2023-10-24 17:56 作者:Kazuma_124 | 我要投稿

int main(){
return 0;//返回0表示程序正常執(zhí)行,非零表示非正常執(zhí)行
}
%n是輸出控制符,將printf函數(shù)已經(jīng)輸出的字符數(shù)存儲(chǔ)到對(duì)應(yīng)的參數(shù)中;
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;報(bào)錯(cuò)
}
void test2() {
int num1 = 10;
const int* ptr = &num1;
//*ptr = 20;報(bào)錯(cuò),ptr為一個(gè)指向常量的指針,它地址指向的值不能修改
int num2 = 20;
ptr = &num2;
num1 = 20;//num1不是常量,可以被修改,但ptr是一個(gè)指向常量的指針,不能利用ptr修改它指向的變量
}
void test3() {
int num1 = 10;
int* const ptr = &num1;
int num2 = 20;
//ptr = &num2;報(bào)錯(cuò),ptr為常量指針,其存儲(chǔ)的地址不能修改
const int(*ptr2) = &num1;
//ptr = &num2;仍報(bào)錯(cuò)
//const優(yōu)先級(jí)比*高,所以單純的const int *標(biāo)識(shí)符;會(huì)優(yōu)先判斷為int型常量,再判斷該變量為指針變量
}
標(biāo)簽: