Output Based Que (2) 2
Output Based Que (2) 2
Output Based Que (2) 2
#include<stdio.h>
int main(){
int x=011,i;
for(i=0;i<x;i+=3){
printf("Start ");
continue;
printf("End");
}
return 0;
}
Output: Start Start Start
#include<stdio.h>
int main(){
int i,j;
i=j=2,3;
while(--i&&j++)
printf("%d %d",i,j);
return 0;
}
Output: 13
Q4. What will be output of following c code?
#include<stdio.h>
int main(){
static int i;
for(++i;++i;++i) {
printf("%d ",i);
if(i==4) break;
}
return 0;
}
Output: 24
Q5. What will be output of following c code?
#include<stdio.h>
int main(){
int i;
for(i=0;i<=5;i++);
printf("%d",i)
return 0;
}
Output: 6
Q6. What will be output of following c code?
#include<stdio.h>
int i=40;
extern int i;
int main(){
do{
printf("%d",i++);
}
while(5,4,3,2,1,0);
return 0;
}
Output: 40
Explanation:
Initial value of variable i is 40
First iteration:
printf function will print i++ i.e. 40
do - while condition is : (5,4,3,2,1,0)
Here comma is behaving as operator and it will return 0. So while condition
is false hence program control will come out of the loop.
Q7. What will be output of following c code?
#include<stdio.h>
int main(){
int i;
for(i=10;i<=15;i++){
while(i){
do{
printf("%d ",1);
if(i>>1)
continue;
}while(0);
break;
}
}
return 0;
}
Output: 1 1 1 1 1 1
For loop will execute six times.
Note: continue keyword in do-while loop bring the program its while
condition (while(0)) which is always false.
Q8. What will be the output of the following program?
#include<stdio.h>
int main()
{
int i=2,j=2;
while(i+1?--i:j++)
printf("i=%d j=%d",i,j);
return 0;
}
Output: 1 2
#include<stdio.h>
void main()
{
int i;
for(i=1,printf("Intialization");printf("\nCondition"),i++
<= 5;printf("%d",i))
printf("\nInside the loop\n");
}
Program 2:
#include<stdio.h>
void main()
{
int i;
for(i=1,printf("Initialization");i++ <=
5,printf("\nCondition");printf("%d",i))
printf("\nInside the loop :");
}
Output:
Program 1:
Initialization
Condition
Inside the loop:2
Condition
Inside the loop:3
Condition
Inside the loop:4
Condition
Inside the loop:5
Condition
Inside the loop:6
Program 2:
Infinite Loop
Q10. What will be the output of the following program?
main ()
{
int i;
for (i=2;i<=10;i++)
{
switch (i)
{
case 2:
printf ("H");
continue;
case 3:
break;
case 4:
case 5:
printf ("m");
break;
default:
printf (!);
}
}
}
Output:
Hmm!!!!!
main()
{
int x = 10, y, z;
z=y=x;
y-= x--;
z -= --x;
x -= --x - x--;
printf ("y = %d z = %d x = %d", y, z, x);
}
Output : y=0z = 2x = 6
Q13. What will be the output of the following program?
main()
{
inta = 10, b = 10;
printf ("ans = %d", a>b?a*a:b/b);
}
Output ans = 1
Q14. What will be output when you will execute following c
code?
#include<stdio.h>
void main(){
int a=5,b=10,c=1;
if(a&&b>c){
printf("cquestionbank");
}
else{
break;
}
}
Output :Compilation error
#include <stdio.h>
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf("%d %d\n", l, k);
return 0;
}
Output: -1 1
Q17. What is the output of this C code?
#include <stdio.h>
void main()
{
int x = 5.3 % 2;
printf("Value of x is %d", x);
}
Output: Compile time error
#include <stdio.h>
int main()
{
int a = 1, b = 1, d = 1;
printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d +
d++ + a++);
}
Output: 14, 4, 5