Question 1 |
Guess the Output of the following program.
int i=1 ; (i == 1 ? printf( "Case 1" ): printf("Case 2"));
Case 2 | |
Compile Error | |
Case 1 | |
Run Time Error |
Question 2 |
What will be the output of the following code ?
int i=1 ; (i == 1 ? printf("Case %d",i): printf("Case 2"));
Run Time Error | |
Compile Error | |
Case 2 | |
Case 1 |
Question 3 |
int num, a=10, b=20, c=30 ; num = (a > b ? ( a > c ? 10: 30 ) : ( b > c ? 20: 30 ) ); printf("%d");Guess the output of the code.
Compile Error | |
30 | |
20 | |
10 |
Question 4 |
Can we use nested statements inside Conditional Statement ?
Yes | |
No |
Question 5 |
Suppose a = 20, b = 10 then guess the output of the following code.
a > b ? temp = a : temp = b;
Value of a is assigned to b | |
Compile Error | |
Value of a is assigned to temp | |
Value of b is assigned to temp |
Question 5 Explanation:
a > b ? temp = a : temp = b;In absence of parentheses the compiler believes that b is being assigned to the result of the expression to the left of second "=". i,e Suppose a>b is true then Compile will interpret it as -
temp = a = bInstead of it write statement like this -
a > b ? temp = a : (temp = b);
Question 6 |
for (i = 0; i < n; i++) printf("%6d%c", a[i], (i%10==9 || i==n-1) ? '\n' : ' ');We are printing the array of size 10. Then each element in this example will be separated by -
New Line | |
Backslash | |
Space | |
Tab |
Question 7 |
#include <stdio.h> int main(int argc, char *argv[]) { int i=0; int n=15; int a[15] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}; for (i = 0; i < n; i++) printf("%6d%c", a[i], (i%10==9 || i==n-1) ? '\n' : ' '); return 0; }What will be the last number printed on the first line.
9 | |
0 | |
1 | |
8 |
Question 8 |
Following Code Snippet Can be written as -
if ( expression1 ) { expression3 } else { expression2 }
statement 2 ? statement 1 : statement 3 | |
statement 1 ? statement 2 : statement 3 | |
statement 2 ? statement 3 : statement 1 | |
statement 1 ? statement 3 : statement 2 |
Question 9 |
What error we will get after compiling following program -
a > b ? temp = a : temp = b ;
Undefined Symbol ? | |
R Value Require | |
Statement Missing } | |
L Value Require |
Question 10 |
Following program will print _________ number.
int num, a=10, b=20, c=30 ; num = (a > b ? ( a > c ? 10: 30 ) : ( b > c ? 20: 30 ) );
Smallest Number | |
Largest Number | |
Random Number | |
Even Number |
There are 10 questions to complete.