Page 1 of 4

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

COMSATS Institute of Information Technology

Abbottabad
Programming Recap Quiz

SECTION – A
Marks: 33
1. What will be the output of the following code:
int c=(2*(3+2))-2;
if (c=>8){ cout<<”greater or equals to 8”;}

a. greater or equals b. Nothing will print c. Error in ‘c’ d. Error in if


to 8 initialization condition
2. Which of the following is not a computer instruction.

a. Ooooo printer, b.
a = b+c c.
Print the value of d.
Read the variable
printer please fill a on the screen. from RAM
yourself with a
black ink
cartridge
3. The variable is an association between

a. Name, address, b. Value, data type, c. Name, address, d. None of the above
data type name value
4. int i = 3;
This declaration tells the C compiler to:

a. Reserve space in b. Associate the c. Store the value 3 d. All the options.
memory to hold name i with the at the location.
the integer value. memory location.
5. What will be output of the following instructions:
float x = 0.9113;
int y = 33;
int z = x + y;
printf(“The answer is %d”, z);

a. error b. Nothing will print c. 33 d. 33.09113


6. There are three ways to set the value of a variable

a. Assignment, b. Ordering, c. Definition, d. Input, output,


initialization, dictating, putting declaration, input declaration.
input
7. An element of an array has the following properties:

a. Name, address, b. Index number c. Name, address, d. None of the given.


data type, value data type, value
and index
8. The _________ begins the body of every function and the _________ ends the body of every
function.
9. Every C program begins execution at the function ______________.
10. After executing the following loop for(int x=0; x<50; x++), the x will contain the value _____.
11. Events that occur while a program is running is said to happen at _______________.

Page 1 of 4
12. When a variable is declared in C its value is _________________.
13. The ___________________ selection statement is used to execute one action when a
condition is true and another action when that condition is false.
14. When it’s known in advance how many times a set of statements will be repeated,
a(n)__________ value is used to terminate the repetition.
15. Repetition of a set of instructions a specific number of times are called _________________
repetition.
16. Setting certain variables to specific values at the beginning of a program is
called_____________.
17. A(n)_____________is a graphical representation of an algorithm.
18. The _____________ statement when executed in a repetition statement or a switch statement,
causes an immediate exit from the statement.
19. The following program is correct
int main(); {
[ ]
printf(“Hello”);
}
20. The compiler ignores comments. [ ]
21. C programming Language is case sensitive. [ ]
22. 1_this_is_variable is a valid C variable name. [ ]
23. The value of a named constant can be inputted at runtime [ ]
24. The result of the remainder/modulus ( % ) operation can be stored in a float. [ ]
25. The break; keyword terminates the program. [ ]
26. In do……while repetition, the condition is checked after the execution of the statements in its
[ ]
scope.
27. In switch…….case multiple, we can use logical conditions. [ ]
28. If and we perform the value of will be 2. [ ]
29. The increment operator ++ is also called prefix. [ ]
30. In for repetition statement variable assignment is a part of the statement. [ ]
31. Arrays are passed by value in a function. [ ]
32. If a function is called by value it makes copies of the variables it receives. [ ]
33. We can only use if……..else if……….else conditional structure for logical conditions. [ ]

Page 2 of 4
SECTION – B
Marks: 21
1. Find the error in each of the following, (Note: There may be more than one errors) 4
a. The following code should print whether a given integer is odd or even.
int check=value%2;
switch(check){
case 0:
cout<<”The value is even”;
case 1:
cout<<”The value is odd”;
}

b. The following code should sum the integers from 100 to 150 (assume total is initialized to
0)
for(x = 100; x <= 150; x++);{
total += x;
}
2. State which values are printed by each of the following repetition statements. 8
a. for(x = 2; x <= 13; x += 2){
cout<< x;
}
b. int i = 7, x = 1;
while(x <= 49){
x = x * i;
cout<< x;
}
c. int sum=0;
for(i = 1; i<=10; i++){
if(i%2 == 0){
sum += i;
}
}
cout<< sum;
d. int it = 0, product = 1;
while (it<5){
product *= ++it;
}
cout<<“The product is”<<product;

3. What will be the output of the following code: 3


char word[6] = {'t', 'u', 'r', 't', 'l', 'e'};
for (int i=0; i<6; i++){
if(word[i] == 't'){
if(i == 0){
word[i] = 'f';
}
else {
word[i] = 'g';
}
}
}
for (int j=0; j<6; j++){
cout<<word[j];
}

Page 3 of 4
4. What will be the output of the following code: 3
int flag = 1, it = 0;
while (it<3){
if (flag == 1){
cout<<"Tic";
flag = 0;
}
else {
cout<<"Toc";
flag = 1;
}
it++;
}
5. For the given 2 dimensional array (its already initialized with name two_d_array) 3

77 68 86 73
96 87 89 78
70 90 86 81

What will be output of the following code:


int i, j, v=100;
for (i = 0; i < 3; i++){
for (j = 0; j < 4; j++){
if(two_d_array[i][j] < v){
v = two_d_array[i][j];
cout<<v;
}
}
}

Page 4 of 4

You might also like