C program 一問 20分

2008-09-16 11:10 am
void abc(char s[])
void abc(char *s)

問題1 : 以上2個其實有咩分別?
問題2 : 應該幾時用*, 幾時唔洗用
問題3 : 用佐而d function有咩好處?

回答 (1)

2008-09-30 2:03 pm
✔ 最佳答案
1. The differences
void abc(char s[]) <= Pass by value
The original value in s[] is not affected by the function.

void abc(char *s) <= Pass by reference
The original value is actually modified in the function.

2. When to use pointer(*)
You will need to use pointer if the argument you try to pass to function is very big. For example char array with length 20000. It is not feasible to make a whole copy in the function because it consumes a lot of memory space.

3. Why use function.
Code reused is the main purpose of function.




收錄日期: 2021-04-13 16:05:49
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080916000051KK00247

檢視 Wayback Machine 備份