Day 2
Day 2
void main()
{
int num=10;
if(num)
printf(“If Executed”);
else
printf(“Else Executed”);
}
Correct Answer
(a) If Executed
(c) Error
(d) Blank
Question: 2
What is the output?
void main()
{
if(-100)
printf(“Negative number”);
else
printf(“Positive number”);
}
Correct Answer
(b) Negative number
(c) Error
No Answerwas selected
Question: 3
What is the output?
void main()
{
if(1 || 0)
printf(“C Programming”);
else
printf(“learn C”);
}
(a) learn C
Correct Answer
(c) C Programming
(d) Error
No Answerwas selected
Question: 4
What is the output?
void main()
{
int x= 5;
if(x < 1);
printf(“Hello”);
printf(“Hi”);
}
(a) Hi
Correct Answer
(b) HelloHi
(c) Error
No Answerwas selected
Question: 5
What is the output?
void main()
{
int x = 5;
if (x < 1)
printf(“hello”);
if (x == 5)
printf(“hi”);
else
printf(“no”);
}
Correct Answer
(a) hi
(b) hello
(c) no
(d) error
No Answerwas selected
Question: 6
What is the output?
void main()
{
int x = 0;
if (x == 0)
printf(“hi”);
else
printf(“how are u”);
printf(“hello”);
}
(a) hi
(c) hello
Correct Answer
(d) hihello
No Answerwas selected
Question: 7
What is the output?
void main()
{
int x = 0;
if (x++)
printf(“true\n”);
else if (x == 1)
printf(“false\n”);
}
(a) true
Correct Answer
(b) false
(c) blank
(d) Error
No Answerwas selected
Question: 8
What is the output?
int main()
{
int x = 0;
if (x == 1)
if (x >= 0)
printf(“true\n”);
else
printf(“false\n”);
}
(a) true
(b) false
Correct Answer
(c) blank
(d) Error
No Answerwas selected
Question: 9
What is alternate name of conditional operator?
Correct Answer
(d) Ternary operator
No Answerwas selected
Question: 10
What will be the output of the following C code ?
void main() {
int i = 0,k;
lable : printf(“%d”,i);
if(i==0)
goto lable;
}
A. 0
Correct Answer
B. infinite 0
C. Nothing
D. Error
No Answerwas selected
Question: 11
What will be the output of the following C code ?
int main() {
int x = 0;
if(x==1)
if(x==0)
printf(“inside if\n”);
else
printf(“inside else if\n”);
else
printf(“inside else\n”);
}
A. inside if
B. inside else if
Correct Answer
C. inside else
No Answerwas selected
Question: 12
What will be the output of the following C code ?
int main() {
int x = 0;
if(x==0)
printf(“true “);
else if(x=10)
printf(“false “);
printf(“%d\n”,x);
}
A. false, 0
Correct Answer
B. true, 0
C. true, 10
D. compile time error
No Answerwas selected
Question: 13
What will be the output of the following C code ?
int main() {
int x = 0;
if(x==1)
if(x>=0)
printf(“true\n”);
else
printf(“false\n”);
}
A. true
B. false
Correct Answer
D. No print statement
No Answerwas selected
Question: 14
What will be the output of the following C code ?
int main() {
int x = 1;
if(x>0)
printf("inside if\n");
else if(x>0)
printf("inside elseif\n");
}
Correct Answer
A. inside if
B. inside elseif
C. inside if
inside elseif
No Answerwas selected
Question: 15
What will be the output of the following C code ?
int main() {
printf(“%d “,1);
goto l1 ;
printf(“%d “,2);
l1: goto l2;
printf(“%d “,3);
l2: printf(“%d “, 4);
}
Correct Answer
A. 1 4
B. Compilation Error
C. 1 2 4
D. 1 3 4
No Answerwas selected
Question: 16
What will be the output of the following C code ?
void main() {
int x = 5;
if(x<1) ;
printf(“Hello”);
}
A. Nothing
Correct Answer
C. Hello
D. Varies
No Answerwas selected
Question: 17
What will be the output of the following C code ?
int main() {
printf(“%d “,1);
l1:l2:
printf(“%d “,2);
printf(“%d\n”,3);
}
A. Compilation error
Correct Answer
B. 1 2 3
C. 1 2
D. 1 3
No Answerwas selected
Question: 18
The C statement if(a==1 || b==2){} can be re - written as ……
A. if(a==1)
if(b==2){}
B. if(a==1){}
if(b==2){}
C. if(a==1){}
else if(b==2){}
Correct Answer
D. None of the above
No Answerwas selected
Question: 19
What will be the output of the following C code ?
int main() {
int a = 1;
if(a){
printf(“All is well “);
}
printf(“I am well\n”);
else {
printf(“I am not a River\n”);
}
}
Correct Answer
D. Compile time errors during compilation
No Answerwas selected
Question: 20
Find the output of the following program.
include
void main()
{
int y=10;
if(y++>9 && y++!=10 && y++>11)
printf(“%d”, y);
else
printf(“%d”, y);
}
a.11
b.12
Correct Answer
c.13
d.14
No Answerwas selected
Question: 21
Determine Ouput :
void main() {
int i = 0,j = 0;
if(i && j++) {
printf(“%d..%d”,i++,j);}
printf(“%d..%d”,i,j);
}
a.0..1
b.1..0
Correct Answer
c.0..0
d.1..1
No Answerwas selected
Question: 22
Determine Output:
void main()
{
int i=-1, j=-1, k=0, l=2, m;
m = i++ && j++ && k++ || l++;
printf(“%d %d %d %d %d”, i, j, k, l, m);
}
a.0 0 1 2 0
b.0 0 1 3 0
Correct Answer
c.0 0 1 3 1
d.0 0 0 2 1
No Answerwas selected
Question: 23
What will be the output of the program?
include
int main()
{
int X=40;
{
int X=20;
printf(“%d “, X);
}
printf(“%d\n”, X);
return 0;
}
a.40 40
Correct Answer
b.20 40
c.20
d.Error
No Answerwas selected
Question: 24
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;
}
a. b = 300 c = 200
b. b = 100 c = garbage
c. b = 300 c = garbage
Correct Answer
d. b = 100 c = 200
No Answerwas selected
Question: 25
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 Answer
a. x and y are equal
c. Unpredictable
d. No output
No Answerwas selected
Question: 26
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 Answer
a. Hi
b. Hello
c. Hi Hello
d. None of above
No Answerwas selected
Question: 27
What will be the output of the program?
include
int main()
{
int k, num = 30;
k = (num < 10) ? 100 : 200;
printf(“%d\n”, num);
return 0;
}
a. 200
Correct Answer
b. 30
c. 100
d. 500
No Answerwas selected
Question: 28
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 Answer
c. 300, Garbage, 200
No Answerwas selected
Question: 29
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 Answer
a. x=2, y=1, z=1
No Answerwas selected
Question: 30
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;
}
b. No output
Correct Answer
c. Error: Expression syntax
int a=5;
switch(a)
{
case 0: printf("0 ");
case 3: printf("3 ");
case 5: printf("5 ");
default: printf("RABBIT ");
}
a=10;
switch(a)
{
case 0: printf("0 ");
case 3: printf("3 ");
case 5: printf("5 ");
default: printf("RABBIT "); break;
}
return 0;
}
5 RABBIT
0 3 5 RABBIT 0 3 5 RABBIT
0 3 5 RABBIT RABBIT
Correct Answer
3 5 RABBIT RABBIT
switch(a)
{
case 2: printf("ZERO "); break;
RABBIT
ZERO RABBIT
No output
Correct Answer
Compiler error
switch(a)
{
printf("MySwitch");
}
Correct Answer
MySwitch
No Output
Compiler Error
switch(a)
{
printf("APACHE ");
}
printf("HEROHONDA");
}
APACHE HEROHONDA
Correct Answer
HEROHONDA
No Output
Compiler error
switch(a);
{
printf("DEER ");
}
printf("LION");
}
LION
Correct Answer
DEER LION
Compiler error