Sunteți pe pagina 1din 16

School of Computer Science & Software Engineering Mid-Semester Test September 2010

C Programming 1210 (CITS1210)

Each question is worth 1 mark. Marks for this paper total 20. Candidates should attempt ALL questions.

Examination candidates may only bring authorised materials into the examination room. If a supervisor nds, during the examination, that you have unauthorised material, in whatever form, in the vicinity of your desk or on your person, whether in the examination room or the toilets or en route to/from the toilets, the matter will be reported to the head of school and disciplinary action will normally be taken against you. This action may result in your being deprived of any credit for this examination or even, in some cases, for the whole unit. This will apply regardless of whether the material has been used at the time it is found. Therefore, any candidate who has brought any unauthorised material whatsoever into the examination room should declare it to the supervisor immediately. Candidates who are uncertain whether any material is authorised should ask the supervisor for clarication.

Sa

mp
This paper contains: 16 pages (including title page) Time allowed: 40 minutes + 5 minutes PLEASE NOTE

This paper contains 1 section

le

Mid-Semester Test C Programming 1210

2 CITS1210

Instructions

This examination is structured as follows: 5 minutes reading time, during which no writing is allowed, followed by 40 minutes writing time. There are 20 questions, each of which is worth 1 mark. For each question, you should select the best answer and ll-in the corresponding entry on the provided answer-sheet. Make sure you follow the directions listed on the answer-sheet.

No written material (books, notes, etc.) or electronic devices (calculators, computers, etc.) are permitted in this test. Use the back pages of this test booklet for rough working. Do not bring anything to your desk other than essential writing materials. At the end of the examination, you need only hand in your answer-sheet; you may keep this test booklet.

Sa

mp

le

Mid-Semester Test C Programming 1210

3 CITS1210

1.

(1) Which of the following statements about the gcc compiler is true?

A. gcc is Apples proprietary ISO-C99 C compiler for the Macintosh platform. B. gcc only compiles C source les that have been recently modied. C. gcc corrects insignicant syntax errors in C source les. D. gcc passes C source code les to a preprocessor. E. gcc enforces the ISO-C99 standard. (2) Consider the following value: argv[1]

What does this value represent?

A. The number of command-line arguments supplied to the program.

B. The rst command-line argument (excluding the name of the program) supplied to the program. C. The second command-line argument (excluding the name of the program) supplied to the program. D. The name of the executing program. E. None of the options A D.

Sa

mp

le

Mid-Semester Test C Programming 1210

4 CITS1210

(3) Consider the following function: void go(void) { int x = 3; if (x < 10) { int x = 5; x = x + 1; printf("x = %d\n", x); } }

What is printed when the go function is executed? A. x = 4

B. x = 6 D. x = 9

C. The ISO-C99 language specication allows either x = 4 or x = 6 to be printed. E. An error is generated because the variable x is multiply dened. (4) Consider the following Boolean expression: a || (!a && b)

Which of the following is equivalent to this expression? A. true B. b

Sa
D. a && !b E. None of the options A D.

C. a || b

mp

le

Mid-Semester Test C Programming 1210

5 CITS1210

(5) Consider the following function: void go(void) { for (int i = 0; i < 3; i++) { for (int j = i; j < 5; j++) { printf("*"); } printf("!\n"); } }

What is printed when the go function is executed? A. ! *! **!

B. *! **! ***!

C. *****! ****! ***! D. ***! **! *! ! !

Sa
E. None of the options A D.

mp

le

Mid-Semester Test C Programming 1210

6 CITS1210

(6) Consider the following function: void go(void) { int i = 10; do { printf("i is %d\n", i); i++; } while (i < 5); }

What is printed when the go function is executed? A. i is 10 B. i i i i i C. i i i i i is is is is is 0 1 2 3 4

is is is is is

D. Nothing no output is produced. E. None of the options A D.

Sa

mp
10 11 12 13 14

le

Mid-Semester Test C Programming 1210

7 CITS1210

(7) Consider the following function: void go(void) { for (int i = 0; i < 5; i++) { if (i == 3) { break; } printf("i is %d\n", i); } }

What is printed when the go function is executed? A. i is 3

B. i is 0 i is 1 i is 2 C. i i i i D. i i i i i is is is is

is is is is is

E. None of the options A D.

Sa

mp
0 1 2 4 0 1 2 3 4

le

Mid-Semester Test C Programming 1210

8 CITS1210

(8) Consider a function of type void. Which of the following statements about the number of return statements contained within the function is true? A. The function must have precisely 0 return statements. B. The function must have precisely 1 return statement.

C. The function must have precisely 0 or 1 return statements. D. The function must have 1 or more return statements.

(9) Consider the following code: void f1(int x) { x = 2; } int f2(int x) { x = 2; return x; }

void go(void) { int x = 5; int y = 5; f1(x); y = f2(x); printf("x = %d, y = %d\n", x, y); }

Sa
A. x = 2, y = 2 B. x = 5, y = 2 C. x = 2, y = 5 D. x = 5, y = 5 E. None of the options A D.

What is printed when the go function is executed?

mp

E. The function may have any number of (including 0) return statements.

le

Mid-Semester Test C Programming 1210

9 CITS1210

(10) Consider the following array denition: #define N 25 int arr[N][N];

A. for(int n=0; n<N; ++n) { arr[n][N-n] = arr[n][N-n]; }

B. for(int n=0; n<N; ++n) { arr[n][N-n-1] = arr[n][N-n-1]; } C. for(int n=0; n<N; ++n) { arr[n][N-n-1] = arr[N-n-1][n]; } D. for(int n=0; n<N; ++n) { int t = arr[n][N-n-1]; arr[n][N-n-1] = arr[n][n]; arr[n][n] = t; } E. for(int i=0; i<N; ++i) { for(int j=N-1; j>=0; --j) { int t = arr[i][j]; arr[i][j] = arr[j][i]; arr[j][i] = t; } }

Sa

mp

Imagine that arr has been initialized such that every element is zero, except the elements on the two main (top-left to bottom-right and top-right to bottom-left) diagonals. Which of the following code fragments will swap the values on the primary (top-left to bottomright) diagonal with those on the other diagonal?

le

Mid-Semester Test C Programming 1210

10 CITS1210

(11) Which of the following statements about arrays in C is/are true? i. ii. iii. Indexing starts from 1. Character arrays are always terminated by the null-byte. Array elements are all of the same data type.

A. None of i., ii., or iii. B. ii. only. C. iii. only. D. ii. and iii. only.

E. None of the options A D.

(12) Which of the following statements about how lines are terminated in text les is true? A. The end of a line is represented by the null-byte character. B. The end of a line is represented by the newline character.

C. The end of a line is represented by the carriage-return character.

D. The end of a line is represented by the carriage-return character followed by the end-of-line character. E. The way the end of a line is represented is operating-system dependent. (13) Consider the following code:

char buffer[50]; fgets(buffer, sizeof buffer, fp);

Which of the following statements about the call to the fgets function is/are true? i. ii. The fgets function reads all the characters in the le up to the next newline character. The fgets function guarantees to place a null-byte in the buffer character array, regardless of the length of the line in the le being read. The fgets function only returns NULL if the end-of-the-le is reached.

Sa
iii. A. i. and ii. only B. i. and iii. only. C. ii. and iii. only. D. All of i., ii., and iii. E. None of the options A D.

mp

le

Mid-Semester Test C Programming 1210

11 CITS1210

(14) Consider the following code: struct Point { int x; int y; }; struct Polygon { int nPoints; struct Point points[50]; }; void go(void) { struct Polygon p; ...

What is the correct way to access the x-coordinate of the rst point in the polygon represented by the variable p? A. p[0].x

B. p[0].points.x C. p.points[0].x D. p.points.x[0]

E. p.x.points[0]

(15) Consider the start of the following function: void go(void) { DIRECTION d; ...

Sa

Which of the following is the correct way to declare an enumeration named DIRECTION for use in this function? A. enum DIRECTION {NORTH, SOUTH, EAST, WEST}; B. enum Direction {NORTH, SOUTH, EAST, WEST} DIRECTION; C. typedef DIRECTION enum {NORTH, SOUTH, EAST, WEST}; E. typedef enum {NORTH, SOUTH, EAST, WEST} DIRECTION;

D. typedef enum DIRECTION {NORTH, SOUTH, EAST, WEST};

mp

le

Mid-Semester Test C Programming 1210

12 CITS1210

(16) Consider the following code: #define triple(x) x * 3

What is printed when the go function is executed? A. Answer = 8

B. Answer = 16 C. Answer = 18 D. Answer = 20

E. None of the options A D. (17) Consider the following function:

void go(void) { for (int i = 0; i < 5; i++) { static int sum = 0; sum += i*i; } printf("sum = %d\n", sum); }

Sa
A. sum = 0 B. sum = 16 C. sum = 30 D. This code will not compile. E. None of the options A D.

What is printed when the go function is executed?

mp

void go(void) { int x = 5; printf("Answer = %d\n", triple(x+1)); }

le

Mid-Semester Test C Programming 1210

13 CITS1210

(18) Which of the following statements about the role of the extern keyword in C is true? A. A variable may be declared as extern multiple times. B. extern allocates memory for global variables. C. extern allocates memory for static variables. D. extern may only appear in header les. E. None of the options A D.

(19) Which of the following statements is a genuine motivation for writing large programs using multiple les? A. The complete program will compile more quickly. B. The complete program will run more quickly. C. All global variables can be removed. E. None of the options A D. D. Dierent les may be edited simultaneously.

(20) Which of the following statements about the make program is true?

A. Commands to control makes execution may appear in les of any name. B. make only runs if its Makefile has been recently modied. D. make enforces ISO-C99 language standards. E. make compiles C programs. C. make reports the errors of syntactically incorrect C programs.

Sa

mp

le

Mid-Semester Test C Programming 1210

14 CITS1210

Use this page for rough working

Sa

mp

le

Mid-Semester Test C Programming 1210

15 CITS1210

Use this page for rough working

Sa

mp

le

Mid-Semester Test C Programming 1210

16 CITS1210

Use this page for rough working

Sa

mp

le

S-ar putea să vă placă și