Final Exam
Final Exam
SECTION A
Multiple Choice Questions
Answer ALL Questions
This section carries 25 marks
1. ____ is a group of related values with the same data type that is stored using a single
group name.
A. Array
B. Struct
C. File
D. Variable
5. An array _____ can be treated as a pointer and used in pointer arithmetic expression.
A. element
B. index
C. name
D. size
9. Re-arrange the following process into proper sequence as per the compilation pipeline.
I. Source Code
II. Assembler
III. Compiler
IV. Linker
V. Machine Executable Code
VI. Preprocessor
10. Which of the following statements is NOT TRUE regarding the function concept?
A. Arguments can be passed to a function using call-by-value or call-by-reference.
B. A function with a return-data-type “void”, will not return the control back to the
caller.
C. Function prototypes enable the compiler to verify that functions are called correctly.
D. The arguments passed to a function should match in number, type and order with the
parameters in the function definition.
11. C provides four storage classes to determine the storage duration, scope and linkage.
These four storage classes are
I. auto III. extern V. register
II. class IV. storage VI. static
A. I,II,III,IV
B. I,III,V,VI
C. I,IV,V,VI
D. I,III,V,VI,
12. A pair of braces ‘{}’ and the portion of the program between the braces is called a
______.
A. Block
B. Program
C. Statements
D. code
14. “while”, “do...while” and “for” are the example of _____ control structure.
A. Sequence
B. selection
C. repetition
D. program
16. The compiler normally issues an error message to help you locate and fix the incorrect
statement. It also known as compile errors, or compile-time errors.
A. Logic errors
B. Runtime errors
C. Syntax errors
D. All of the above
18. The _____ statement is called a multiple-selection statement because it selects among
many different actions.
A. switch
B. If
C. If…else
D. else…if
20. The file open mode____ indicates that the file is to be opened for writing. If the file does
not exist, fopen creates the file. If the exists, the contents are discarded without warning.
A. a
B. c
C. r
D. w
21. A linked list is a linear collection of self-referential structures, called nodes. Which of the
following is self-referential structure?
A.
struct Node {
char data;
struct Node *nextPtr;
};
B.
struct Node {
char data;
};
C.
Node {
Node *nextPtr;
};
D.
Node {
char data;
};
22. How many times the block of code will run when x is assigned with 1 in the following
snippet of code?
while(x<10){
sum += x;
x++;
}
A. 1
B. 10
C. 9
D. Unknown
23. Given the following snippet of code, what the program trying to achieve?
for ( i = 1; i < SIZE; i++ ) {
for ( j= 0; j < SIZE – 1; j++ ) {
if (a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]= temp;
}
}
}
A. Sort the values in the array ‘a’ in ascending order
B. Sort the values in the array ‘a’ in descending order
C. Move the values in the array ‘a’ into the next index sequence.
D. Iterate through each value in the array ‘a’.
24. The _____ searching method works well for small or unsorted arrays.
A. linear
B. binary
C. bubble
D. file
25. What is the format conversion specifier used to read character with scanf function.
A. %d
B. %s
C. %c
D. %f
SECTION B
Answer ALL questions
This section carries 25 marks
Question B1
Following program will receive an input (height) from the operator and print the bottom left
triangle pattern (*) using C function concept based on the height. You are required to fill in
the blanks in the program.
__a___ <stdio.h>
void PrintBottomLeftTrianglePattern(_b___); //function
prototype
int main() {
int height;
do{
printf("Enter height: ");
scanf("__c__",__d__); //read user input, height
if(__e___) // check the height, value should be 1 or
more
printf("Invalid value, please enter height again!\
n");
}while(height<=0);
printf("\n----Bottom Left Triangle Pattern----\n");
____f_____(height); //function call
return 0;
}
//function definition
void PrintBottomLeftTrianglePattern(int height){
int __g___,col;
for (row =0; row<height; row++) {
for(col=0;__h__; col++)
printf("__i_"); //print pattern "*"
printf("_j__"); //print newline
}
}
Sample input-output
[10 marks]
Question B2
b) Given a =1,b=2,c=3 and d=4, what will be the output of the following expression?
i. a+b*c
ii. c*d/b
iii. a%b
iv. ++c
v. c==d
vi. b?a:b
vii. -d
[7 marks]
[3 marks]