高普考題庫
110 年 110年公務人員高等考試三級考試暨普通考試・程式設計概要
申論 4程式語言C 可使用不同資料型別的變數存取資料與傳遞函式的參數。#include <stdio.h>#include <stdlib.h>#include <string.h>void myFunction(int *a, int b, int *c, char *d){c[1] = *a + b;d[*c] = d[2];b = 17;int *r = c + 1;c = a;*c = *a + 1;printf("during:%s %d %d %d %d\n", &d[1], *a, b, *c, *r);}int main(){char animal[7] = "cat";int x = strlen(animal);int z[3] = {1, 3, 5};int * y =(int *)malloc(sizeof(int)*3);int *p = &x;int *q = &z[1];q[1] = *p + 10;printf("before:%s %d %d %d %d\n", animal, *z, z[1], z[2], x);myFunction(p, x, q, animal);printf("after:%s %d %d %d %d\n", animal, z[0], z[1], z[2], x);return 0;}㈠請說明上述程式執行的結果。(15 分)㈡請說明比較C 程式宣告一個陣列時,如上述程式變數y、z,使用一般陣列變數與指標變數的異同。(5 分)㈢請說明比較C 程式語言中,函式參數傳遞方法,傳值呼叫(call by value)與傳址呼叫(call by address)異同。(5 分)