Vous êtes sur la page 1sur 8

Chapter 10 Features of Array, Linked List, Queue and Stack Question Bank

Chapter 10 Features of Array, Linked List, Queue and Stack


Multiple Choice Questions

(U02C10L01Q001)
Which of the following array initialization statements is valid?
A. int ary[ ] = [1, 2, 3, 4];
B. int ary[ ] = {1, 2, 3, 4};
C. int ary[4] = [1, 2, 3, 4];
D. int ary{4} = [1, 2, 3, 4];
Answer
B

(U02C10L01Q002)
Which of the following statements assigns the value stored in x to the first element on an array,
ary?
A. ary = x[0];
B. ary = x[1];
C. ary[1] = x;
D. ary[0] = x;
Answer
D

(U02C10L01Q003)
Which of the following statements about two-dimensional arrays is correct?
A. Only the size of the second dimension needs to be declared when he array is used as a
parameter.
B. Two different types can be stored in a two-dimensional array.
C. A two-dimensional array can be thought of as an array of one-dimensional array.
D. The first dimension is known as the column dimension.
Answer
C

Computer & Information Technology for HKCEE 1 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 10 Features of Array, Linked List, Queue and Stack Question Bank

(U02C10L01Q004)
How many elements are there in the following definition of array table?
int table[5][4];
A. 5
B. 4
C. 9
D. 20
Answer
D

(U02C10L01Q005)
Which of the following array declarations can declare an array to hold the 9 × 9 multiplication
table?
A. int table[9];
B. int table[9][9];
C. int table[3][3];
D. int table[18];
Answer
B

(U02C10L01Q006)
What is the output of the following program segment?
for (i=1; i<=10; i++)
for (j=1; j<=10; j++)
a[i][j] = i*j;
printf("%d\n", a[4][3] – a[3][4]);
A. 0
B. 3
C. 12
D. 24
Answer
A

Computer & Information Technology for HKCEE 2 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 10 Features of Array, Linked List, Queue and Stack Question Bank

(U02C10L01Q007)
Which of the following statements correctly initialize the whole array to zeros?
A. int table[5][4] = {0};
B. int table[0][0];
C. int table[][];
D. int table[5][4] = {};
Answer
A

(U02C10L01Q008)
What is the output of the following program?
#include <stdio.h>
void main(){
char chararray[10];
int intarray[] = {2,1,3,5,4,8,3,7};
double dblarray[8] = {1.2, 3.4, -2.3, 1.4, 4.5};
int index;
for (index=0; index<10; index++)
chararray[index] = 127 - index;
printf("%d %d %d", sizeof(chararray),
sizeof(intarray), sizeof(dblarray));
}
A. 10 16 64
B. 16 10 64
C. 64 16 10
D. 64 10 16
Answer
A

(U02C10L01Q009)
What can be said about the following?
int high_scores[ ] = {97, 86, 98, 100};
A. It is an integer array.
B. The array has four elements.
C. The array is named high_scores.
D. All of the above.
Answer
D

Computer & Information Technology for HKCEE 3 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 10 Features of Array, Linked List, Queue and Stack Question Bank

(U02C10L01Q010)
Which of the following declares a two-dimensional array?
A. int pick_me[2][2];
B. int pick_me[0][2];
C. int pick_me[2,2];
D. int two_dimensional_array;
Answer
A

Computer & Information Technology for HKCEE 4 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 10 Features of Array, Linked List, Queue and Stack Question Bank

Conventional Questions

(U02C10L02Q001)
A program creates an empty array that can hold 20 elements, numbered 0 through 19. Then the
program fills those elements with the numbers 1 through 20, and then 20 through 1.
The output sample:
Initialize array from 1 to 20:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
And now from 20 to 1:
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
(10 marks)
Answers
#include <stdio.h>
#define ELEMENTS 20
void main(){
int blorf[ELEMENTS];
int x;
/*First pass, fill array with values 1 through 20 */
printf("Initialize array from 1 to 20:\n");
for (x=0;x<ELEMENTS;x++){
blorf[x] = x+1;
printf("%i\x20", blorf[x]);
}
/*Second pass, fill array with values 20 through 1 */
printf("\nAnd now from 20 to 1:\n");
for (x=0;x<ELEMENTS;x++){
blorf[x]=20-x;
printf("%i\x20", blorf[x]);
}
}

Computer & Information Technology for HKCEE 5 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 10 Features of Array, Linked List, Queue and Stack Question Bank

(U02C10L02Q002)
Consider the following program.

#include <stdio.h>
#include <string.h>
void main(){
char phrase[] = "I like Computer";
int x, size;
printf("\"%s\"\n", phrase);
size = strlen(phrase);
printf("That phrase is %i characters long.\n", size);
for (x=0;x<size;x++)
printf("phrase[%i]='%c'\n",x, phrase[x]);
}
What are the outputs of phrase[1]and phrase[6]?
(2 marks)
Answers
phrase[1] and phrase[6] are ' '.

(U02C10L02Q003)
What would be printed by the following program?
#include <stdio.h>
int main(void){
/* Local definition */
int list[10] = {2, 1, 2, 1, 2, 3, 2, 1, 2};
/* Statements */
printf("%d\n", list[2]);
printf("%d\n", list[list[2]]);
printf("%d\n", list[list[2]+list[3]]);
printf("%d\n", list[list[list[2]]]);
return 0;
}
(4 marks)
Answers
The output is
2
2
1
2
Computer & Information Technology for HKCEE 6 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 10 Features of Array, Linked List, Queue and Stack Question Bank

(U02C10L02Q004)
What would be printed by the following program?
#include <stdio.h>
int main(void){
/* Local definition */
int list[10] = {2, 1, 2, 4, 1, 2, 0, 2, 1, 2};
int line[10];
int i;
/* Statements */
for (i=0;i<10;i++)
line[i]=list[9-i];
for (i=0;i<10;i++)
printf("%d %d\n", list[i], line[i]);
return 0;
}
(3 marks)
Answers
The output is
2 2
1 1
2 2
4 0
1 2
2 1
0 4
2 2
1 1
2 2

Computer & Information Technology for HKCEE 7 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 10 Features of Array, Linked List, Queue and Stack Question Bank

(U02C10L02Q005)
Use the multidimensional array to display a multiplication table for positive integer products
between 0 * 0 and 3 * 4.
The output is
0 0 0 0 0
0 1 2 3 4
0 2 4 6 8
0 3 6 9 12

(13 marks)
Answers
#include <stdio.h>
void printab(int rows, int columns, int array[][5]);
int main(void){
int multiarray[4][5], row, column;
for (row=0;row<4;row++)
for (column=0;column<5;column++)
multiarray[row][column] = row * column;
printab(4, 5, multiarray);
return 0;
}
void printab(int rows, int columns, int array[][5]){
int i = 0, j = 0;
while(i<rows){
printf("%d%c", array[i][j],(j==columns-1)?'\n':'\t');
(j==columns-1)? i++, j=0: j++;
}
}

Computer & Information Technology for HKCEE 8 © Pearson Education Asia Limited 2004
(Module A1)

Vous aimerez peut-être aussi