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

Mood independent programming

C/C++ Question/Answers
Difficulty Level Rating Sheet
Instructions
1. Please fill the cell in front of the question/answer with the appropriate difficulty
level word from (Difficult, Medium, and Easy). Also consider that every question
has at most one minute to answer. Please see the example below.
Question Answer Difficulty Level
What is a pointer? 1. An arrow Easy
2. Memory variable
3. Address of some
memory part

Actual Table to be rated

Question(s) Answers Difficulty Level


Which of the following C++ statements contain variables 1. Parts (a) and (b).
whose values are replaced? 2. Parts (b) and (c)
a) cin >> b >> c >> d >> e >> f; 3. Parts (d) and (a)
b) p = i + j + k + 7; 4. Parts (c) and (a)
c) cout << "variables whose values are destroyed";
d) cout << "a = 5";
Which variable value is not changed 1. Variable a
int a, b=3, c=2, d; 2. Variable b
a = b+c; 3. Variable c
d = a + c; 4. all variables
a = a – (b+c); changed
What is the order of evaluation of the operators in each of the 1. *,%,/,-,+,=; x=4
following C++ statement? Also state the value of x. 2. %,*,/,+,-,=; x=3
b) x = 2 % 2 + 2 * 2 - 2 / 2; 3. +,-,%,*,/,=; x=0
4. No one is correct
What is the order of evaluation of the operators in each of the 1. *,/,*,*,+,=; x=24
following C++ statement? Also state the value of x. 2. No one is correct
3. +,*,*,/,*,=; x=32
x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) ); 4. *,/,+,*,*,=; x=324
Identify and correct the error(s) in the following: 1. No error
2. else not properly
if ( age >= 65 ); used
cout << "Age is greater than or equal to 65" << endl; 3. Semicolon after if
else 4. Both 2 and 3
cout << "Age is less than 65” << endl;
What is error(logical, syntax) in the following 1. No Error
2. Infinite loop
int x = 5; 3. One time
while (x > 0); execution
x--; 4. loop execute five
times
What is error (logical, syntax) in the following. 1. x pre incremented
int x = 1, total; 2. No error
while ( x <= 10 ) { 3. while never
total += x; executes
++x; 4. total not
} initialized
int main() 1. n is not
{ initialized
float sum; 2. sum is not
int n=1, count=0; initialized
3. count++ will
while (n > 0) never execute
{
scanf("%d", &n);
sum = sum + n;
count++;
}
return(0);
}
What is the error (logical, syntax) in the following code 1. counter should be
segment? The code should output the even integers from 2 to initialized in loop
100: 2. While should be
counter = 2; while. Operator <
do { should be <=.
cout << counter << endl; 3. No error
counter += 2; 4. both 1 and 2
} While ( counter < 100 );
What is the output of the following code segment 1. 2 3 5 7
2. 1 2 3 7
int i, j, c=0; 3. There is error
for (i=2; i<10; i++) { in this code
for (j=1; j<=i; j++)
{
if (i%j==0)
c++;
}
if (c==2)
cout<<i<<” “;
c=0;
}
What is error (logical, syntax) in the following. 1. No error
2. No float type
float cube( float ); // function prototype returns
double cube( float number ) // function definition specification.
{ 3. function prototype
return number * number * number; not matching
} 4. Both 2 and 3
main() 1. Fun will
{ //function call give syntax
Fun(4.5); error
} 2. there is no
error
void Fun(int n) 3. the correct
{ cout << n; } value will not
be printed by
Fun()
What is the error (logical, syntax) in the following. 1. variable number
is declared twice
double square( double number ) 2. No error
{ 3. return type no
double number; matching
return number * number;
}
Assume that: double d[ 2 ][ 10 ]; 1. No d[1,9] location
d[ 1, 9 ] = 2.345; exists
2. No error
3. Not correct
syntax
4. both 1 and 3
What is error (logical, syntax) in the following. 1. No base case
define
int sum( int n ) 2. Infinite recursion
{ 3. No error
if ( n == 0 ) 4. Both 1 and 2
return 0;
else
return n + sum( n );
}
main() 1. No base case
{ 2. Infinite
cout << recursive_call(5); recursion
} 3. No error
both 1 and 2
int recursive_call(int n)
{
return recursive_call(n-1);
}
Assume that: int a[ 3 ]; 1. No error
cout << a[ 1 ] << " " << a[ 2 ] << " " << a[ 3 ] << endl; 2. Syntax error
3. A[3] is not valid
location
What is the logical error in the following code? 1. line 2 print 10
2. line 2 print
1 int Array[10] = {1,2,3,4,5,6,7,8,9,10}; nothing
2 printf("%d",Array[10]); 3. line 2 print
garbage value
4. There is no error
Double f[ 3 ] = { 1.1, 10.01, 100.001, 1000.0001 }; 1. too many
intializers
2. No matching
values in initializing
list
3. Both 1 and 2
4. No error
int x = 10; 1. There is
if (1 == x) compa-rison error
printf(“X is 1”); 2. There is no
error
3. printf never
exec-utes
What will be the output of the following code 1. 3212
2. 4212
int x = 3; 3. 4323
cout << x++ << “ “; 4. None
x--;
--x;
cout<<x << “ “;
cout<< --x<<” “;
x+=2;
cout<< --x;
What is the output of the following code segment 1. 2 1 3 1
2. No output
int i,j; 3. 2 1 2 2 3 1 3
for (i=2;i<4;++i) 2
for (j=1;j<3;++j) 4. Error in code
cout << i << “ “ << j << “ “;
What is the error (logical, Syntax) in the lines of code? 1. No error
2. break is not used
int x; 3. case 2 and 3
cin >> x; always execute
switch( x ) 4. incorrect syntax
{
case 2:
printf("Two\n");
case 3:
printf("Three\n");
}
What is error (logical, syntax) in the following code segment 1. No error
2. string are
char snum[5] = “One”; being matched
int sum=0; in switch
switch(snum) 3. break is not
{ used in default
case “One”: case
sum+= 10;
break;
case “Two”:
sum+= 100;
break;
default:
sum+= 1000;
}

You might also like