c programming 高手入

2012-01-06 8:10 am
void print1(int *, int);<~~~呢個係點解 ? 好似唔係FUNCTION 黎WO
main() {
int list[ ] = {3, 4, 5, 6, 7};
print1(list, 5);
}
void print1(int *ptr, int rows) { <~~~`又會REPEAT GE
int i ;
printf("Address contents\n");
for(i=0; i<rows; i++ )
printf("%8u%5d\n", ptr+i, *(ptr+i));
printf("\n");
system("PAUSE");
}

回答 (2)

2012-01-06 9:14 am
✔ 最佳答案
void print1(int *, int);
This is the function declaration

All identifiers in C need to be declared before they are used. This is true for functions as well as variables. For functions the declaration needs to be before the first call of the function. A full declaration includes the return type and the number and type of the arguments. This is also called the function prototype.

If you do not use function declaration, the function definition (the complete function) must be put before the first call to the function.
2012-01-07 6:54 am
...好簡單,

void print1(int *, int); 一定會放係main()之前,
佢係用尼宣告有function個名叫 print1, 同埋有2個参數, 型態
分別係 int* 同 int。

當main() function執行後, 如果你會用到 print1() 呢個function,
佢會自己係main()後面搵一個個名叫 print1 ge function。

所以, 之後你會見到 void print1(int *ptr, int rows),
佢先係真正ge function。

當然, 你可以唔寫void print1(int *, int); , 而放整段function係main()
之前, 咁做連宣告都唔洗。


收錄日期: 2021-04-23 21:30:23
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20120106000051KK00009

檢視 Wayback Machine 備份