Looping questions and answers with explanation for written test exam and interview in c programming language
         
         
         
         
(1)
What will be output of following c code?
#include<stdio.h>
extern int x;
int main(){
    do{
        do{
             printf("%o",x);
         }
         while(!-2);
    }
    while(0);
    return 0;
}
int x=8;
EXPLANATION
(2)
What will be output of following c code?
#include<stdio.h>
int main(){
    int i=2,j=2;
    while(i+1?--i:j++)
         printf("%d",i);
    return 0;
}
EXPLANATION
(3)
What will be output of following c code?
#include<stdio.h>
int main(){
    int x=011,i;
    for(i=0;i<x;i+=3){
         printf("Start ");
         continue;
         printf("End");
    }
    return 0;
}
EXPLANATION
(4)What will be output of following c code?
#include<stdio.h>
int main(){
    int i,j;
    i=j=2,3;
    while(--i&&j++)
         printf("%d %d",i,j);
    return 0;
}
EXPLANATION
(5)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;
}
EXPLANATION
(6)What will be output of following c code?
#include<stdio.h>
int main(){
    int i=1;
    for(i=0;i=-1;i=1) {
         printf("%d ",i);
         if(i!=1) break;
    }
    return 0;
}
EXPLANATION
(7)What will be output of following c code?
#include<stdio.h>
int main(){
    for(;;) {
         printf("%d ",10);
    }
    return 0;
}
EXPLANATION
(8)What will be output of following c code?
#include<stdio.h>
int r();
int main(){
    for(r();r();r()) {
         printf("%d ",r());
    }
    return 0;
}
int r(){
    int static num=7;
    return num--;
}
EXPLANATION
(9)What will be output of following c code?
#include<stdio.h>
#define p(a,b) a##b
#define call(x) #x
int main(){
    do{
         int i=15,j=3;
         printf("%d",p(i-+,+j));
    }
    while(*(call(625)+3));
    return 0;
}
EXPLANATION
(10)
#include<stdio.h>
int main(){
    int i;
    for(i=0;i<=5;i++);
    printf("%d",i)
    return 0;
}
EXPLANATION
(11)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;
}
EXPLANATION
(12)What will be output of following c code?
#include<stdio.h>
char _x_(int,...);
int main(){
    char (*p)(int,...)=&_x_;
    for(;(*p)(0,1,2,3,4); )
         printf("%d",!+2);
    return 0;
}
char _x_(int a,...){
    static i=-1;
    return i+++a;
}
EXPLANATION
(13)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;
}
EXPLANATION
(14)How many times this loop will execute?
#include<stdio.h>
int main(){
    char c=125;
    do
         printf("%d ",c);
    while(c++);
    return 0;
}
EXPLANATION
(15)What will be output of following c code?
#include<stdio.h>
int main(){
    int x=123;
    int i={
         printf("c" "++")
    };
    for(x=0;x<=i;x++){
         printf("%x ",x);
    }
    return 0;
}
No comments:
Post a Comment