C Programming Control Instructions Online Test
Finish Quiz
0 of 30 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
Information
C Programming Control Instructions Online Test. C Programming Online Question and Answers in English.C Programming Online Quiz. C Programming Control Instructions Online mock test paper is free for all students and Very Helpful for Exam Preparation. C Programming Control Instructions Online Quiz. C Programming Online Mock test for Control Instructions Topic. Here we are providing C Programming Control Instructions Online Test Series in English. Check C Programming Mock Test Series 2019-2019.
This paper has 30 questions.
Time allowed is 30 minutes.
The C Programming online Mock Test Exam is Very helpful for all students. Now Scroll down below n click on “Start Quiz” or “Start Test” and Test yourself.
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 30 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Average score |
|
Your score |
|
Categories
- Not categorized 0%
Pos. | Name | Entered on | Points | Result |
---|---|---|---|---|
Table is loading | ||||
No data available | ||||
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- Answered
- Review
-
Question 1 of 30
1. Question
How many times “IndiaBIX” is get printed?
#include
int main() { int x; for(x=-1; x10; x++) { if(x 5) continue; else break; printf("IndiaBIX"); } return 0; } Correct
Incorrect
-
Question 2 of 30
2. Question
How many times the while loop will get executed if a short int is 2 byte wide?
#include
int main() { int j=1; while(j 255) { printf("%c %d\n", j, j); j++; } return 0; } Correct
The while(j loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.
Incorrect
The while(j loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.
-
Question 3 of 30
3. Question
Which of the following is not logical operator?
Correct
Bitwise operators:
& is a Bitwise AND operator.Logical operators:
&& is a Logical AND operator.
|| is a Logical OR operator.
! is a NOT operator.So, ‘&‘ is not a Logical operator.
Incorrect
Bitwise operators:
& is a Bitwise AND operator.Logical operators:
&& is a Logical AND operator.
|| is a Logical OR operator.
! is a NOT operator.So, ‘&‘ is not a Logical operator.
-
Question 4 of 30
4. Question
In mathematics and computer programming, which is the correct order of mathematical operators ?
Correct
Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).
Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.
Incorrect
Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).
Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.
-
Question 5 of 30
5. Question
Which of the following cannot be checked in a switch-case statement?
Correct
The switch/case statement in the c language is defined by the language specification to use an int value, so you can not use a float value.
switch( expression ) { case constant-expression1: statements 1; case constant-expression2: statements 2; case constant-expression3: statements3 ; ... ... default : statements 4; }
The value of the ‘expression‘ in a switch-case statement must be an integer, char, short, long. Float and double are not allowed.
Incorrect
The switch/case statement in the c language is defined by the language specification to use an int value, so you can not use a float value.
switch( expression ) { case constant-expression1: statements 1; case constant-expression2: statements 2; case constant-expression3: statements3 ; ... ... default : statements 4; }
The value of the ‘expression‘ in a switch-case statement must be an integer, char, short, long. Float and double are not allowed.
-
Question 6 of 30
6. Question
What will be the output of the program?
#include
int main() { int i=0; for(; i5; i++); printf("%d", i); return 0; } Correct
Step 1: int i = 0; here variable i is an integer type and initialized to ‘0’.
Step 2: for(; i variable i=0 is already assigned in previous step. The semi-colon at the end of this for loop tells, “there is no more statement is inside the loop”.Loop 1: here i=0, the condition in for(; 0i is incremented by ‘1’(one)
Loop 2: here i=1, the condition in for(; 1i is incremented by ‘1’(one)
Loop 3: here i=2, the condition in for(; 2i is incremented by ‘1’(one)
Loop 4: here i=3, the condition in for(; 3i is increemented by ‘1’(one)
Loop 5: here i=4, the condition in for(; 4i is incremented by ‘1’(one)
Loop 6: here i=5, the condition in for(; 5i is incremented by ‘1’(one)
Loop 7: here i=6, the condition in for(; 6i is not incremented.Step 3: printf(“%d”, i); here the value of i is 6. Hence the output is ‘6’.
Incorrect
Step 1: int i = 0; here variable i is an integer type and initialized to ‘0’.
Step 2: for(; i variable i=0 is already assigned in previous step. The semi-colon at the end of this for loop tells, “there is no more statement is inside the loop”.Loop 1: here i=0, the condition in for(; 0i is incremented by ‘1’(one)
Loop 2: here i=1, the condition in for(; 1i is incremented by ‘1’(one)
Loop 3: here i=2, the condition in for(; 2i is incremented by ‘1’(one)
Loop 4: here i=3, the condition in for(; 3i is increemented by ‘1’(one)
Loop 5: here i=4, the condition in for(; 4i is incremented by ‘1’(one)
Loop 6: here i=5, the condition in for(; 5i is incremented by ‘1’(one)
Loop 7: here i=6, the condition in for(; 6i is not incremented.Step 3: printf(“%d”, i); here the value of i is 6. Hence the output is ‘6’.
-
Question 7 of 30
7. Question
What will be the output of the program?
#include
int main() { char str[]="C-program"; int a = 5; printf(a >10?"Ps\n":"%s\n", str); return 0; } Correct
Step 1: char str[]=”C-program”; here variable str contains “C-program”.
Step 2: int a = 5; here variable a contains “5”.
Step 3: printf(a >10?”Ps\n”:”%s\n”, str); this statement can be written asif(a > 10) { printf("Ps\n"); } else { printf("%s\n", str); }
Here we are checking a > 10 means 5 > 10. Hence this condition will be failed. So it prints variable str.
Hence the output is “C-program”.
Incorrect
Step 1: char str[]=”C-program”; here variable str contains “C-program”.
Step 2: int a = 5; here variable a contains “5”.
Step 3: printf(a >10?”Ps\n”:”%s\n”, str); this statement can be written asif(a > 10) { printf("Ps\n"); } else { printf("%s\n", str); }
Here we are checking a > 10 means 5 > 10. Hence this condition will be failed. So it prints variable str.
Hence the output is “C-program”.
-
Question 8 of 30
8. Question
What will be the output of the program?
#include
int main() { int a = 500, b = 100, c; if(!a >= 400) b = 300; c = 200; printf("b = %d c = %d\n", b, c); return 0; } Correct
Initially variables a = 500, b = 100 and c is not assigned.
Step 1: if(!a >= 400)
Step 2: if(!500 >= 400)
Step 3: if(0 >= 400)
Step 4: if(FALSE) Hence the if condition is failed.
Step 5: So, variable c is assigned to a value ‘200’.
Step 6: printf(“b = %d c = %d\n”, b, c); It prints value of b and c.
Hence the output is “b = 100 c = 200”Incorrect
Initially variables a = 500, b = 100 and c is not assigned.
Step 1: if(!a >= 400)
Step 2: if(!500 >= 400)
Step 3: if(0 >= 400)
Step 4: if(FALSE) Hence the if condition is failed.
Step 5: So, variable c is assigned to a value ‘200’.
Step 6: printf(“b = %d c = %d\n”, b, c); It prints value of b and c.
Hence the output is “b = 100 c = 200” -
Question 9 of 30
9. Question
What will be the output of the program?
#include
int main() { unsigned int i = 65535; /* Assume 2 byte integer*/ while(i++ != 0) printf("%d",++i); printf("\n"); return 0; } Correct
Here unsigned int size is 2 bytes. It varies from 0,1,2,3, … to 65535.
Step 1:unsigned int i = 65535;
Step 2:
Loop 1: while(i++ != 0) this statement becomes while(65535 != 0). Hence the while(TRUE) condition is satisfied. Then the printf(“%d”, ++i); prints ‘1’(variable ‘i’ is already incremented by ‘1’ in while statement and now incremented by ‘1’ in printf statement) Loop 2: while(i++ != 0) this statement becomes while(1 != 0). Hence the while(TRUE) condition is satisfied. Then the printf(“%d”, ++i); prints ‘3’(variable ‘i’ is already incremented by ‘1’ in while statement and now incremented by ‘1’ in printf statement)
….
….The while loop will never stops executing, because variable i will never become ‘0’(zero). Hence it is an ‘Infinite loop’.
Incorrect
Here unsigned int size is 2 bytes. It varies from 0,1,2,3, … to 65535.
Step 1:unsigned int i = 65535;
Step 2:
Loop 1: while(i++ != 0) this statement becomes while(65535 != 0). Hence the while(TRUE) condition is satisfied. Then the printf(“%d”, ++i); prints ‘1’(variable ‘i’ is already incremented by ‘1’ in while statement and now incremented by ‘1’ in printf statement) Loop 2: while(i++ != 0) this statement becomes while(1 != 0). Hence the while(TRUE) condition is satisfied. Then the printf(“%d”, ++i); prints ‘3’(variable ‘i’ is already incremented by ‘1’ in while statement and now incremented by ‘1’ in printf statement)
….
….The while loop will never stops executing, because variable i will never become ‘0’(zero). Hence it is an ‘Infinite loop’.
-
Question 10 of 30
10. Question
What will be the output of the program?
#include
int main() { int x = 3; float y = 3.0; if(x == y) printf("x and y are equal"); else printf("x and y are not equal"); return 0; } Correct
Step 1: int x = 3; here variable x is an integer type and initialized to ‘3’.
Step 2: float y = 3.0; here variable y is an float type and initialized to ‘3.0’
Step 3: if(x == y) here we are comparing if(3 == 3.0) hence this condition is satisfied.
Hence it prints “x and y are equal”.Incorrect
Step 1: int x = 3; here variable x is an integer type and initialized to ‘3’.
Step 2: float y = 3.0; here variable y is an float type and initialized to ‘3.0’
Step 3: if(x == y) here we are comparing if(3 == 3.0) hence this condition is satisfied.
Hence it prints “x and y are equal”. -
Question 11 of 30
11. Question
What will be the output of the program, if a short int is 2 bytes wide?
#include
int main() { short int i = 0; for(i5 && i>=-1; ++i; i>0) printf("%u,", i); return 0; } Correct
for(i=-1; ++i; i>0) so expression i=-1 initializes for loop. expression ++i is the loop condition. expression i>0 is the increment expression.
In for( i = -1; ++i; i>0) expression i=-1 evaluates to one.
Loop condition always get evaluated to true. Also at this point it increases i by one.
An increment_expression i>0 has no effect on value of i.so for loop get executed till the limit of integer (ie. 65535)
Incorrect
for(i=-1; ++i; i>0) so expression i=-1 initializes for loop. expression ++i is the loop condition. expression i>0 is the increment expression.
In for( i = -1; ++i; i>0) expression i=-1 evaluates to one.
Loop condition always get evaluated to true. Also at this point it increases i by one.
An increment_expression i>0 has no effect on value of i.so for loop get executed till the limit of integer (ie. 65535)
-
Question 12 of 30
12. Question
What will be the output of the program?
#include
int main() { char ch; if(ch = printf("")) printf("It matters\n"); else printf("It doesn't matters\n"); return 0; } Correct
printf() returns the number of charecters printed on the console.
Step 1: if(ch = printf(“”)) here printf() does not print anything, so it returns ‘0’(zero).
Step 2: if(ch = 0) here variable ch has the value ‘0’(zero).
Step 3: if(0) Hence the if condition is not satisfied. So it prints the else statements.
Hence the output is “It doesn’t matters”.Note: Compiler shows a warning “possibly incorrect assinment”.
Incorrect
printf() returns the number of charecters printed on the console.
Step 1: if(ch = printf(“”)) here printf() does not print anything, so it returns ‘0’(zero).
Step 2: if(ch = 0) here variable ch has the value ‘0’(zero).
Step 3: if(0) Hence the if condition is not satisfied. So it prints the else statements.
Hence the output is “It doesn’t matters”.Note: Compiler shows a warning “possibly incorrect assinment”.
-
Question 13 of 30
13. Question
What will be the output of the program?
#include
int main() { unsigned int i = 65536; /* Assume 2 byte integer*/ while(i != 0) printf("%d",++i); printf("\n"); return 0; } Correct
Here unsigned int size is 2 bytes. It varies from 0,1,2,3, … to 65535.
Step 1:unsigned int i = 65536; here variable i becomes ‘0’(zero). because unsigned int varies from 0 to 65535.
Step 2: while(i != 0) this statement becomes while(0 != 0). Hence the while(FALSE) condition is not satisfied. So, the inside the statements of while loop will not get executed.
Hence there is no output.
Note: Don’t forget that the size of int should be 2 bytes. If you run the above program in GCC it may run infinite loop, because in Linux platform the size of the integer is 4 bytes.
Incorrect
Here unsigned int size is 2 bytes. It varies from 0,1,2,3, … to 65535.
Step 1:unsigned int i = 65536; here variable i becomes ‘0’(zero). because unsigned int varies from 0 to 65535.
Step 2: while(i != 0) this statement becomes while(0 != 0). Hence the while(FALSE) condition is not satisfied. So, the inside the statements of while loop will not get executed.
Hence there is no output.
Note: Don’t forget that the size of int should be 2 bytes. If you run the above program in GCC it may run infinite loop, because in Linux platform the size of the integer is 4 bytes.
-
Question 14 of 30
14. Question
What will be the output of the program?
#include
int main() { float a = 0.7; if(0.7 > a) printf("Hi\n"); else printf("Hello\n"); return 0; } Correct
if(0.7 > a) here a is a float variable and 0.7 is a double constant. The double constant 0.7 is greater than the float variable a. Hence the if condition is satisfied and it prints ‘Hi’
Example:#include
int main() { float a=0.7; printf("%.10f %.10f\n",0.7, a); return 0; } Output:
0.7000000000 0.6999999881Incorrect
if(0.7 > a) here a is a float variable and 0.7 is a double constant. The double constant 0.7 is greater than the float variable a. Hence the if condition is satisfied and it prints ‘Hi’
Example:#include
int main() { float a=0.7; printf("%.10f %.10f\n",0.7, a); return 0; } Output:
0.7000000000 0.6999999881 -
Question 15 of 30
15. Question
What will be the output of the program?
#include
int main() { int a=0, b=1, c=3; *((a) ? &b : &a) = a ? b : c; printf("%d, %d, %d\n", a, b, c); return 0; } Correct
Step 1: int a=0, b=1, c=3; here variable a, b, and c are declared as integer type and initialized to 0, 1, 3 respectively.
Step 2: *((a) ? &b : &a) = a ? b : c; The right side of the expression(a?b:c) becomes (0?1:3). Hence it return the value ‘3’.
The left side of the expression *((a) ? &b : &a) becomes *((0) ? &b : &a). Hence this contains the address of the variable a *(&a).
Step 3: *((a) ? &b : &a) = a ? b : c; Finally this statement becomes *(&a)=3. Hence the variable a has the value ‘3’.
Step 4: printf(“%d, %d, %d\n”, a, b, c); It prints “3, 1, 3”.
Incorrect
Step 1: int a=0, b=1, c=3; here variable a, b, and c are declared as integer type and initialized to 0, 1, 3 respectively.
Step 2: *((a) ? &b : &a) = a ? b : c; The right side of the expression(a?b:c) becomes (0?1:3). Hence it return the value ‘3’.
The left side of the expression *((a) ? &b : &a) becomes *((0) ? &b : &a). Hence this contains the address of the variable a *(&a).
Step 3: *((a) ? &b : &a) = a ? b : c; Finally this statement becomes *(&a)=3. Hence the variable a has the value ‘3’.
Step 4: printf(“%d, %d, %d\n”, a, b, c); It prints “3, 1, 3”.
-
Question 16 of 30
16. Question
What will be the output of the program?
#include
Correct
Incorrect
-
Question 17 of 30
17. Question
What will be the output of the program?
#include
int main() { int a = 300, b, c; if(a >= 400) b = 300; c = 200; printf("%d, %d, %d\n", a, b, c); return 0; } Correct
Step 1: int a = 300, b, c; here variable a is initialized to ‘300’, variable b and c are declared, but not initialized.
Step 2: if(a >= 400) means if(300 >= 400). Hence this condition will be failed.
Step 3: c = 200; here variable c is initialized to ‘200’.
Step 4: printf(“%d, %d, %d\n”, a, b, c); It prints “300, garbage value, 200”. because variable b is not initialized.Incorrect
Step 1: int a = 300, b, c; here variable a is initialized to ‘300’, variable b and c are declared, but not initialized.
Step 2: if(a >= 400) means if(300 >= 400). Hence this condition will be failed.
Step 3: c = 200; here variable c is initialized to ‘200’.
Step 4: printf(“%d, %d, %d\n”, a, b, c); It prints “300, garbage value, 200”. because variable b is not initialized. -
Question 18 of 30
18. Question
What will be the output of the program?
#include
int main() { int x=1, y=1; for(; y; printf("%d %d\n", x, y)) { y = x++ 5; } printf("\n"); return 0; } Correct
Incorrect
-
Question 19 of 30
19. Question
What will be the output of the program?
#include
int main() { int i = 5; while(i-- >= 0) printf("%d,", i); i = 5; printf("\n"); while(i-- >= 0) printf("%i,", i); while(i-- >= 0) printf("%d,", i); return 0; } Correct
Step 1: Initially the value of variable i is ‘5’.
Loop 1: while(i– >= 0) here i = 5, this statement becomes while(5– >= 0) Hence the while condition is satisfied and it prints ‘4’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 2: while(i– >= 0) here i = 4, this statement becomes while(4– >= 0) Hence the while condition is satisfied and it prints ‘3’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 3: while(i– >= 0) here i = 3, this statement becomes while(3– >= 0) Hence the while condition is satisfied and it prints ‘2’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 4: while(i– >= 0) here i = 2, this statement becomes while(2– >= 0) Hence the while condition is satisfied and it prints ‘1’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 5: while(i– >= 0) here i = 1, this statement becomes while(1– >= 0) Hence the while condition is satisfied and it prints ‘0’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 6: while(i– >= 0) here i = 0, this statement becomes while(0– >= 0) Hence the while condition is satisfied and it prints ‘-1’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 7: while(i– >= 0) here i = -1, this statement becomes while(-1– >= 0) Hence the while condition is not satisfied and loop exits.
The output of first while loop is 4,3,2,1,0,-1Step 2: Then the value of variable i is initialized to ‘5’ Then it prints a new line character(\n).
See the above Loop 1 to Loop 7 .
The output of second while loop is 4,3,2,1,0,-1Step 3: The third while loop, while(i– >= 0) here i = -1(because the variable ‘i’ is decremented to ‘-1’ by previous while loop and it never initialized.). This statement becomes while(-1– >= 0) Hence the while condition is not satisfied and loop exits.
Hence the output of the program is
4,3,2,1,0,-1
4,3,2,1,0,-1Incorrect
Step 1: Initially the value of variable i is ‘5’.
Loop 1: while(i– >= 0) here i = 5, this statement becomes while(5– >= 0) Hence the while condition is satisfied and it prints ‘4’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 2: while(i– >= 0) here i = 4, this statement becomes while(4– >= 0) Hence the while condition is satisfied and it prints ‘3’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 3: while(i– >= 0) here i = 3, this statement becomes while(3– >= 0) Hence the while condition is satisfied and it prints ‘2’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 4: while(i– >= 0) here i = 2, this statement becomes while(2– >= 0) Hence the while condition is satisfied and it prints ‘1’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 5: while(i– >= 0) here i = 1, this statement becomes while(1– >= 0) Hence the while condition is satisfied and it prints ‘0’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 6: while(i– >= 0) here i = 0, this statement becomes while(0– >= 0) Hence the while condition is satisfied and it prints ‘-1’. (variable ‘i’ is decremented by ‘1’(one) in previous while condition)
Loop 7: while(i– >= 0) here i = -1, this statement becomes while(-1– >= 0) Hence the while condition is not satisfied and loop exits.
The output of first while loop is 4,3,2,1,0,-1Step 2: Then the value of variable i is initialized to ‘5’ Then it prints a new line character(\n).
See the above Loop 1 to Loop 7 .
The output of second while loop is 4,3,2,1,0,-1Step 3: The third while loop, while(i– >= 0) here i = -1(because the variable ‘i’ is decremented to ‘-1’ by previous while loop and it never initialized.). This statement becomes while(-1– >= 0) Hence the while condition is not satisfied and loop exits.
Hence the output of the program is
4,3,2,1,0,-1
4,3,2,1,0,-1 -
Question 20 of 30
20. Question
What will be the output of the program?
#include
int main() { int i=3; switch(i) { case 1: printf("Hello\n"); case 2: printf("Hi\n"); case 3: continue; default: printf("Bye\n"); } return 0; } Correct
The keyword continue cannot be used in switch case. It must be used in for or while or do while loop. If there is any looping statement in switch case then we can use continue.
Incorrect
The keyword continue cannot be used in switch case. It must be used in for or while or do while loop. If there is any looping statement in switch case then we can use continue.
-
Question 21 of 30
21. Question
What will be the output of the program?
#include
int main() { int x = 10, y = 20; if(!(!x) && x) printf("x = %d\n", x); else printf("y = %d\n", y); return 0; } Correct
The logical not operator takes expression and evaluates to true if the expression is false and evaluates to false if the expression is true. In other words it reverses the value of the expression.
Step 1: if(!(!x) && x)
Step 2: if(!(!10) && 10)
Step 3: if(!(0) && 10)
Step 3: if(1 && 10)
Step 4: if(TRUE) here the if condition is satisfied. Hence it prints x = 10.Incorrect
The logical not operator takes expression and evaluates to true if the expression is false and evaluates to false if the expression is true. In other words it reverses the value of the expression.
Step 1: if(!(!x) && x)
Step 2: if(!(!10) && 10)
Step 3: if(!(0) && 10)
Step 3: if(1 && 10)
Step 4: if(TRUE) here the if condition is satisfied. Hence it prints x = 10. -
Question 22 of 30
22. Question
What will be the output of the program?
#include
int main() { int i=4; switch(i) { default: printf("This is default\n"); case 1: printf("This is case 1\n"); break; case 2: printf("This is case 2\n"); break; case 3: printf("This is case 3\n"); } return 0; } Correct
In the very begining of switch-case statement default statement is encountered. So, it prints “This is default”.
In default statement there is no break; statement is included. So it prints the case 1 statements. “This is case 1”.
Then the break; statement is encountered. Hence the program exits from the switch-case block.
Incorrect
In the very begining of switch-case statement default statement is encountered. So, it prints “This is default”.
In default statement there is no break; statement is included. So it prints the case 1 statements. “This is case 1”.
Then the break; statement is encountered. Hence the program exits from the switch-case block.
-
Question 23 of 30
23. Question
What will be the output of the program?
#include
int main() { int i = 1; switch(i) { printf("Hello\n"); case 1: printf("Hi\n"); break; case 2: printf("\nBye\n"); break; } return 0; } Correct
switch(i) has the variable i it has the value ‘1’(one).
Then case 1: statements got executed. so, it prints “Hi”. The break; statement make the program to be exited from switch-case statement.
switch-case do not execute any statements outside these blocks case and default
Hence the output is “Hi”.
Incorrect
switch(i) has the variable i it has the value ‘1’(one).
Then case 1: statements got executed. so, it prints “Hi”. The break; statement make the program to be exited from switch-case statement.
switch-case do not execute any statements outside these blocks case and default
Hence the output is “Hi”.
-
Question 24 of 30
24. Question
What will be the output of the program?
#include
int main() { char j=1; while(j 5) { printf("%d, ", j); j = j+1; } printf("\n"); return 0; } Correct
Incorrect
-
Question 25 of 30
25. Question
What will be the output of the program?
#include
int main() { int x, y, z; x=y=z=1; z = ++x || ++y && ++z; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0; } Correct
Step 1: x=y=z=1; here the variables x ,y, z are initialized to value ‘1’.
Step 2: z = ++x || ++y && ++z; becomes z = ( (++x) || (++y && ++z) ). Here ++x becomes 2. So there is no need to check the other side because ||(Logical OR) condition is satisfied.(z = (2 || ++y && ++z)). There is no need to process ++y && ++z. Hence it returns ‘1’. So the value of variable z is ‘1’
Step 3: printf(“x=%d, y=%d, z=%d\n”, x, y, z); It prints “x=2, y=1, z=1”. here x is increemented in previous step. y and z are not increemented.
Incorrect
Step 1: x=y=z=1; here the variables x ,y, z are initialized to value ‘1’.
Step 2: z = ++x || ++y && ++z; becomes z = ( (++x) || (++y && ++z) ). Here ++x becomes 2. So there is no need to check the other side because ||(Logical OR) condition is satisfied.(z = (2 || ++y && ++z)). There is no need to process ++y && ++z. Hence it returns ‘1’. So the value of variable z is ‘1’
Step 3: printf(“x=%d, y=%d, z=%d\n”, x, y, z); It prints “x=2, y=1, z=1”. here x is increemented in previous step. y and z are not increemented.
-
Question 26 of 30
26. Question
Which of the following statements are correct about the below program?
#include
int main() { int i = 10, j = 20; if(i = 5) && if(j = 10) printf("Have a nice day"); return 0; } Correct
“Expression syntax” error occur in this line if(i = 5) && if(j = 10).
It should be like if((i == 5) && (j == 10)).
Incorrect
“Expression syntax” error occur in this line if(i = 5) && if(j = 10).
It should be like if((i == 5) && (j == 10)).
-
Question 27 of 30
27. Question
Which of the following statements are correct about the below program?
#include
int main() { int i = 10, j = 15; if(i % 2 = j % 3) printf("IndiaBIX\n"); return 0; } Correct
if(i % 2 = j % 3) This statement generates “LValue required error”. There is no variable on the left side of the expression to assign (j % 3).
Incorrect
if(i % 2 = j % 3) This statement generates “LValue required error”. There is no variable on the left side of the expression to assign (j % 3).
-
Question 28 of 30
28. Question
Which of the following statements are correct about the program?
#include
int main() { int x = 30, y = 40; if(x == y) printf("x is equal to y\n"); else if(x > y) printf("x is greater than y\n"); else if(x "x is less than y\n") return 0; } Correct
This program will result in error “Statement missing ;”
printf(“x is less than y\n”) here ; should be added to the end of this statement.
Incorrect
This program will result in error “Statement missing ;”
printf(“x is less than y\n”) here ; should be added to the end of this statement.
-
Question 29 of 30
29. Question
Which of the following statements are correct about an if-else statements in a C-program?
1: Every if-else statement can be replaced by an equivalent statements using ?: operators
2: Nested if-else statements are allowed.
3: Multiple statements in an if block are allowed.
4: Multiple statements in an else block are allowed.Correct
Incorrect
-
Question 30 of 30
30. Question
Which of the following sentences are correct about a for loop in a C program?
1: for loop works faster than a while loop.
2: All things that can be done using a for loop can also be done using a while loop.
3: for(;;); implements an infinite loop.
4: for loop can be used if we want statements in a loop get executed at least once.Correct
Incorrect