作者amidofun ()
看板Grad-ProbAsk
標題[理工] [DS] 程式
時間Sat Mar 20 17:10:22 2010
請高手幫我看看答案對不對
解救我的指標吧
有心有好報
7.Write the output of the following program. (8%)
int a, b;
for (a=1, b=1; a<=100; a++) {
if (b>=18) break;
if (b%3==1) {
b+=2;
continue;
}
b++;
printf("b = %d\n", b);
}
printf("a = %d", a);
===================================================
OUTPUT: b = 4
b = 7
b = 10
b = 13
b = 16
b = 19
a = 6
===================================================
8.Write the output of the following program. (8%)
void add(int x, int* y, int* w, int **p)
{
static int z = 2;
*w = z++;
x++; y++; (*p)++;
}
int main(void)
{
int a[] = { 2, 4, 6, 8, 10, 12, 14 };
int i, x = 5, *y = a+1, z = 0, *q = a+2;
int **p = &q;
for (i=0; i<3; i++) {
add(x, y, &z, p);
printf("%d, %d, %d, %d\n", x, *y, z, *q);
}
return 0;
}
======================================================
OUTPUT:卡住 指標好難阿 請高手指教
======================================================
9. Write the output of the following program. (6%)
#define M(a,b) a*b
int main(void)
{
int i = 5, j = 6;
printf(”i*j = %d”, M(i+2, j-2*2));
return 0;
}
======================================================
OUTPUT: i*j = 14
======================================================
10. Rewrite and correct the following program. (8%)
include [stdio.h]
int main(void)
{
int i=1, j=5
If (i < j)
i++; j--;
else /* i >= j
printf(”% >= %”, &i, &j);
return 0;
}
======================================================
OUTPUT: 3 >= 3
======================================================
11. Which could be the second line of the program? (multiple-choice, more
than one answer) (6%)
int i=1, j=2;
(a) int *p[2] = {&i, &j};
(b) int (*p)[2] = {&i, &j};
(c) int* p[2] = {&i, &j};
(d) int p[2] = {&i, &j};
======================================================
ANS: 又是指標 卡住
======================================================
12. Which are NOT the keywords in C? (multiple-choice, more than one answer)
(6%)
(a) which (b) void
(c) until (d) signed
(e) static (f) then
======================================================
ANS:(a)
======================================================
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.32.102.8
推 assassin88:只看了第七題..就覺得你錯很大= =" 03/20 17:13
※ 編輯: amidofun 來自: 218.32.102.8 (03/20 17:15)
→ amidofun:拍謝 少貼一行 03/20 17:15
※ 編輯: amidofun 來自: 218.32.102.8 (03/20 17:16)
推 assassin88:喔喔 那第七就沒錯 其實看&前 你要先搞懂 call by valu 03/20 17:19
→ assassin88:e/call by address 這兩種概念 03/20 17:19
→ amidofun:z=0 那&z是位址吧 但我不知道要傳啥 03/20 17:21
→ amidofun:第一輪x=6 z=3?? *y和*q我就看不懂了 03/20 17:38
→ amidofun:x三輪都是5? 03/20 17:42
推 soldier723:第八題題目有沒有打錯呀? 03/20 21:15
※ 編輯: amidofun 來自: 218.32.102.8 (03/20 22:36)
→ amidofun:sorry 以修正 03/20 22:37
→ amidofun:拍謝 少一行 03/20 22:41
推 soldier723:5,4,2,8 ; 5,4,3,10 ; 5,4,4,12 我丟到C裡面去跑的= = 03/21 00:03