Important Questions on Control statements in C

Bhavna Sharma 2:49 pm

Jan 10 • Notes • 2850 Views • 10 Comments on Important Questions on Control statements in C

1) What will be output when you will execute following c code?
#include<stdio.h>
void main(){
if(0xA)
if(052)
if(‘xeb’)
if(’12’)
printf(“Our Edu”);
else;
else;
else;
else;

}

ans: Our Edu (condition is always true)

2) In C Is it possible to write else clause without any body?

ans: yes

3) What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=10;
if(printf(“%d”,a>=10)-10)
for(;;)
break;
else;

}

ans: compilation error ( a>=10 will return 1 since a is equal to 10.Thus printf function will print 1.now the function printf(“%d”,a>=10) – 10

= 1 – 10= -9

Since -9 is non-zero no. so if(-9) is true condition ,if clause will execute which contains an infinite loop but due to break keyword it will come out of loop).

4) What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=5,b=10;
if(++a||++b)
printf(“%d  %d”,a,b);
else
printf(“Doraemon”);

}

ans: 6,10

5) What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int x=1;
if(x–)
printf(India”);
–x;
else
printf(“%d”,x);
}

ans: compilation error

6) main( )
{
int i, j ;
for ( i = 1 ; i <= 2 ; i++ )
{
for ( j = 1 ; j <= 2 ; j++ )
{
if ( i == j )
continue ;
printf ( “n%d %dn”, i, j ) ;
}
}
}

ans: 1 2

2 1

7) How many times “Our edublog” is printed?

#include<stdio.h>

int main()

{ int x;

for(x=-1; x<=10; x++)

{

if(x < 5)

continue;

else break;

printf(“Our edublog”);

}

return 0;

}

ans: 0

8) Which of the following cannot be checked in a switch-case statement?
A.    enum    B.    Float
C.    Integer    D.    Character

ans: float

9) Can we use a switch statement to switch on strings?

ans: No

10) By default, the data type of a constant without a decimal point is int, whereas the one with a decimal point is?

ans: double

Please rate this

Related Posts

10 Responses to Important Questions on Control statements in C

  1. amulya says:

    i want qusetions basec on c,c++,java which will asked interviews

Leave a Reply

Your email address will not be published. Required fields are marked *

« »

Read previous post:
Important Questions of Transformer

Transformer is an electrical device that makes the transfer of energy by forming inductive coupling between the winding of its...

Close