- 2
- 0
- 约2.54千字
- 约 5页
- 2016-11-26 发布于天津
- 举报
指標(pointer)的介紹
指標(pointer)的介紹
變數:表示儲存該變數的記憶體位址。
*位址:表示此記憶體位址內儲存的資料。
指標變數的宣告:
型態 *變數名稱;
型態將決定
指標能夠存取的資料長度
當對指標變數進行加減時,該指標內所存記憶體位址數值的增量。
int value=50;
int *ptr;
ptr = value; // 將value的位址存入ptr; 所以 *ptr 就會是 value;int *iptr, notPointer;
float *fptr, *isPointer;
以C來說,字串就是陣列,就是字元的陣列。因此,字串變數名稱本身就是該陣列的起始位置。所以在使用scanf(.)輸入字串時,可以不必在其前加上表示取出變數位址的符號。
char msg[10];
printf(“Input a string:”);
scanf(%s”, msg); or // scanf(資料格式, 資料所在的位址)
scanf(“%s”, msg) 均可。
(%d: decimal; %f: floating point; %c: char; %s: string)
void getString()
{
char msg[10]; // 存(10-1)個字元,位置可能不夠, 資料會無法完整儲存。
printf(Input the string:);
原创力文档

文档评论(0)