You are on page 1of 4

Mood independent programming C/C++ Question/Answers Difficulty Level Rating Sheet

Instructions
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

1.

Actual Table to be rated
Question(s) Which of the following C++ statements contain variables whose values are replaced? a) cin >> b >> c >> d >> e >> f; b) p = i + j + k + 7; c) cout << "variables whose values are destroyed"; d) cout << "a = 5"; Which variable value is not changed int a, b=3, c=2, d; a = b+c; d = a + c; a = a – (b+c); What is the order of evaluation of the operators in each of the following C++ statement? Also state the value of x. b) x = 2 % 2 + 2 * 2 - 2 / 2; What is the order of evaluation of the operators in each of the following C++ statement? Also state the value of x. x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) ); Identify and correct the error(s) in the following: if ( age >= 65 ); cout << "Age is greater than or equal to 65" << endl; else cout << "Age is less than 65” << endl; What is error(logical, syntax) in the following int x = 5; while (x > 0); x--; What is error (logical, syntax) in the following. int x = 1, total; while ( x <= 10 ) { total += x; ++x; Answers 1. Parts (a) and (b). 2. Parts (b) and (c) 3. Parts (d) and (a) 4. Parts (c) and (a) 1. Variable a 2. Variable b 3. Variable c 4. all variables changed 1. *,%,/,-,+,=; x=4 2. %,*,/,+,-,=; x=3 3. +,-,%,*,/,=; x=0 4. No one is correct 1. *,/,*,*,+,=; x=24 2. No one is correct 3. +,*,*,/,*,=; x=32 4. *,/,+,*,*,=; x=324 1. No error 2. else not properly used 3. Semicolon after if 4. Both 2 and 3 1. No Error 2. Infinite loop 3. One time execution 4. loop execute five times 1. x pre incremented 2. No error 3. while never executes 4. total not Difficulty Level

}

initialized

int main() { float sum; int n=1, count=0; while (n > 0) { scanf("%d", &n); sum = sum + n; count++; } return(0); }
What is the error (logical, syntax) in the following code segment? The code should output the even integers from 2 to 100: counter = 2; do { cout << counter << endl; counter += 2; } While ( counter < 100 ); What is the output of the following code segment int i, j, c=0; for (i=2; i<10; i++) { 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. float cube( float ); // function prototype double cube( float number ) // function definition { return number * number * number; }

1. n is not initialized 2. sum is not initialized 3. count++ will never execute

1. counter should be initialized in loop 2. While should be while. Operator < should be <=. 3. No error 4. both 1 and 2 1. 2 3 5 7 2. 1 2 3 7 3. There is error in this code

1. No error 2. No float type returns specification. 3. function prototype not matching 4. Both 2 and 3

main() { //function call Fun(4.5); } void Fun(int n) { cout << n; }
What is the error (logical, syntax) in the following.

1. Fun will give syntax error 2. there is no error 3. the correct value will not be printed by Fun()
1. variable number

double square( double number ) { double number; return number * number; } Assume that: double d[ 2 ][ 10 ]; d[ 1, 9 ] = 2.345;

is declared twice 2. No error 3. return type no matching 1. No d[1,9] location exists 2. No error 3. Not correct syntax 4. both 1 and 3 1. No base case define 2. Infinite recursion 3. No error 4. Both 1 and 2

What is error (logical, syntax) in the following. int sum( int n ) { if ( n == 0 ) return 0; else return n + sum( n ); }

main() { cout << recursive_call(5); } int recursive_call(int n) { return recursive_call(n-1); }
Assume that: int a[ 3 ]; cout << a[ 1 ] << " " << a[ 2 ] << " " << a[ 3 ] << endl; What is the logical error in the following code? 1 int Array[10] = {1,2,3,4,5,6,7,8,9,10}; 2 printf("%d",Array[10]); Double f[ 3 ] = { 1.1, 10.01, 100.001, 1000.0001 };

1. No base case

2.

Infinite

recursion 3. No error both 1 and 2

1. No error 2. Syntax error 3. A[3] is not valid location 1. line 2 print 10 2. line 2 print nothing 3. line 2 print garbage value 4. There is no error 1. too many intializers 2. No matching values in initializing list 3. Both 1 and 2 4. No error

int x = 10; if (1 == x) printf(“X is 1”);

There is compa-rison error 2. There is no error 3. printf never exec-utes

1.

What will be the output of the following code int x = 3; cout << x++ << “ “; x--; --x; cout<<x << “ “; cout<< --x<<” “; x+=2; cout<< --x; What is the output of the following code segment int i,j; for (i=2;i<4;++i) for (j=1;j<3;++j) cout << i << “ “ << j << “ “; What is the error (logical, Syntax) in the lines of code? int x; cin >> x; switch( x ) { case 2: printf("Two\n"); case 3: printf("Three\n"); } What is error (logical, syntax) in the following code segment char snum[5] = “One”; int sum=0; switch(snum) { case “One”: sum+= 10; break; case “Two”: sum+= 100; break; default: sum+= 1000; }

1. 2. 3. 4.

3212 4212 4323 None

1. 2 1 3 1 2. No output 3. 2 1 2 2 3 1 3 2 4. Error in code 1. No error 2. break is not used 3. case 2 and 3 always execute 4. incorrect syntax

1. No error 2. string are being matched in switch 3. break is not used in default case