Java C Control Statement Quiz 3 | Java C Control Question and Answers
Finish Quiz
0 of 20 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
Information
Java C Control Statement Quiz 3 | Java C Control Question and Answers. Test your java fundamentals with our Free Java C Control Statement online test. Take our Free Java C Control Statement online Quiz free from below….. Java C Control Statement Quiz 3 Question and Answers 2024. Java online Test Quiz 3. Java C Control Stmt. Quiz 3 Free Mock Test 2024. Java C Control Stmt. Quiz 3 Question and Answers in PDF. The Java online mock test paper is free for all students. Spring Online is very useful for exam preparation and getting for Rank. Java C Control Stmt. Quiz 3 Question and Answers in English. Java C Control Stmt. Mock test for topic via C Control Stmt. Mode. Here we are providing Java C Control Stmt. Quiz in English Now Test your self for “C Control Stmt. Online Quiz in English” Exam by using below quiz…
This paper has 20 questions.
Time allowed is 25 minutes.
The Java C Control Stmt. Mock Test 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 20 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
- Answered
- Review
-
Question 1 of 20
1. Question
Point out the error, if any in the while loop.
#include<stdio.h>
int main()
{
void fun();
int i = 1;
while(i <= 5)
{
printf(“%d “, i);
if(i>2)
goto here;
}
return 0;
}
void fun()
{
here:
printf(“It works”);
}Correct
A label is used as the target of a goto statement, and that label must be within the same function as the goto statement.
Syntax: goto <identifier> ;
Control is unconditionally transferred to the location of a local label specified by <identifier>.
Example:#include <stdio.h>
int main()
{
int i=1;
while(i>0)
{
printf(“%d”, i++);
if(i==5)
goto mylabel;
}
mylabel:
return 0;
}Output: 1,2,3,4
Incorrect
A label is used as the target of a goto statement, and that label must be within the same function as the goto statement.
Syntax: goto <identifier> ;
Control is unconditionally transferred to the location of a local label specified by <identifier>.
Example:#include <stdio.h>
int main()
{
int i=1;
while(i>0)
{
printf(“%d”, i++);
if(i==5)
goto mylabel;
}
mylabel:
return 0;
}Output: 1,2,3,4
-
Question 2 of 20
2. Question
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
printf(“This is c program.”);
case 1:
printf(“Case1”);
break;
case 2:
printf(“Case2”);
break;
}
return 0;
}Correct
switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints “Case1”.
printf(“This is c program.”); is ignored by the compiler.
Hence there is no error and prints “Case1”.Incorrect
switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints “Case1”.
printf(“This is c program.”); is ignored by the compiler.
Hence there is no error and prints “Case1”. -
Question 3 of 20
3. Question
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int P = 10;
switch(P)
{
case 10:
printf(“Case 1”);case 20:
printf(“Case 2”);
break;case P:
printf(“Case 2”);
break;
}
return 0;
}Correct
The compiler will report the error “Constant expression required” in the line case P: . Because, variable names cannot be used with case statements.
The case statements will accept only constant expression.Incorrect
The compiler will report the error “Constant expression required” in the line case P: . Because, variable names cannot be used with case statements.
The case statements will accept only constant expression. -
Question 4 of 20
4. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
int i=0;
for(; i<=5; 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<=5; 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(; 0<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 2: here i=1, the condition in for(; 1<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 3: here i=2, the condition in for(; 2<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 4: here i=3, the condition in for(; 3<=5; i++) loop satisfies and then i is increemented by ´1´(one)
Loop 5: here i=4, the condition in for(; 4<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 6: here i=5, the condition in for(; 5<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 7: here i=6, the condition in for(; 6<=5; i++) loop fails and then i 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<=5; 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(; 0<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 2: here i=1, the condition in for(; 1<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 3: here i=2, the condition in for(; 2<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 4: here i=3, the condition in for(; 3<=5; i++) loop satisfies and then i is increemented by ´1´(one)
Loop 5: here i=4, the condition in for(; 4<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 6: here i=5, the condition in for(; 5<=5; i++) loop satisfies and then i is incremented by ´1´(one)
Loop 7: here i=6, the condition in for(; 6<=5; i++) loop fails and then i is not incremented.
Step 3: printf(“%d”, i); here the value of i is 6. Hence the output is ´6´. -
Question 5 of 20
5. Question
Which of the following errors would be reported by the compiler on compiling the program given below?
#include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
case 1:
printf(“First”);case 2:
printf(“Second”);case 3 + 2:
printf(“Third”);case 5:
printf(“Final”);
break;}
return 0;
}Correct
Because, case 3 + 2: and case 5: have the same constant value 5.
Incorrect
Because, case 3 + 2: and case 5: have the same constant value 5.
-
Question 6 of 20
6. Question
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int a = 10, b;
a >=5 ? b=100: b=200;
printf(“%d “, b);
return 0;
}Correct
Variable b is not assigned.
It should be like:
b = a >= 5 ? 100 : 200;Incorrect
Variable b is not assigned.
It should be like:
b = a >= 5 ? 100 : 200; -
Question 7 of 20
7. Question
What will be the output of the program?
#include
int main()
{
char str[]=”C-program”;
int a = 5;
printf(a >10?”Ps “:”%s “, 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 “:”%s “, str); this statement can be written asif(a > 10)
{
printf(“Ps “);
}
else
{
printf(“%s “, 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 “:”%s “, str); this statement can be written asif(a > 10)
{
printf(“Ps “);
}
else
{
printf(“%s “, 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 20
8. Question
Point out the error, if any in the while loop.
#include<stdio.h>
int main()
{
int i=1;
while()
{
printf(“%d “, i++);
if(i>10)
break;
}
return 0;
}Correct
The while() loop must have conditional expression or it shows “Expression syntax” error.
Example: while(i > 10){ … }
Incorrect
The while() loop must have conditional expression or it shows “Expression syntax” error.
Example: while(i > 10){ … }
-
Question 9 of 20
9. Question
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case 1:
printf(“Case1”);
break;
case 1*2+4:
printf(“Case2”);
break;
}
return 0;
}Correct
Constant expression are accepted in switch
It prints “Case1”
Incorrect
Constant expression are accepted in switch
It prints “Case1”
-
Question 10 of 20
10. Question
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int a = 10;
switch(a)
{
}
printf(“This is c program.”);
return 0;
}Correct
There can exists a switch statement, which has no case.
Incorrect
There can exists a switch statement, which has no case.
-
Question 11 of 20
11. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
unsigned int i = 65535; /* Assume 2 byte integer*/
while(i++ != 0)
printf(“%d”,++i);
printf(” “);
return 0;
}Correct
Incorrect
-
Question 12 of 20
12. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
int x, y, z;
x=y=z=1;
z = ++x || ++y && ++z;
printf(“x=%d, y=%d, z=%d “, 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 “, 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 “, 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 13 of 20
13. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
int i=3;
switch(i)
{
case 1:
printf(“Hello “);
case 2:
printf(“Hi “);
case 3:
continue;
default:
printf(“Bye “);
}
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 14 of 20
14. 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(i<=5 && i>=-1; ++i; i>0)
printf(“%u,”, i);
return 0;
}Correct
for(i<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes for loop. expression ++i is the loop condition. expression i>0 is the increment expression.
In for( i <= 5 && i >= -1; ++i; i>0) expression i<=5 && 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<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes for loop. expression ++i is the loop condition. expression i>0 is the increment expression.
In for( i <= 5 && i >= -1; ++i; i>0) expression i<=5 && 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 15 of 20
15. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
int a = 300, b, c;
if(a >= 400)
b = 300;
c = 200;
printf(“%d, %d, %d “, a, b, c);
return 0;
}Correct
Incorrect
-
Question 16 of 20
16. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
char j=1;
while(j < 5)
{
printf(“%d, “, j);
j = j+1;
}
printf(” “);
return 0;
}Correct
Incorrect
-
Question 17 of 20
17. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
int a=0, b=1, c=3;
*((a) ? &b : &a) = a ? b : c;
printf(“%d, %d, %d “, 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 “, 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 “, a, b, c); It prints “3, 1, 3”.
-
Question 18 of 20
18. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
unsigned int i = 65536; /* Assume 2 byte integer*/
while(i != 0)
printf(“%d”,++i);
printf(” “);
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 19 of 20
19. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
c = 200;
printf(“b = %d c = %d “, 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 “, 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 “, b, c); It prints value of b and c.
Hence the output is “b = 100 c = 200” -
Question 20 of 20
20. Question
What will be the output of the program?
#include<stdio.h>
int main()
{
int k, num = 30;
k = (num < 10) ? 100 : 200;
printf(“%d “, num);
return 0;
}Correct
Incorrect