Looping Questions in C and Answers: (1) What Is The Output of The Following Program
Looping Questions in C and Answers: (1) What Is The Output of The Following Program
Output: 1 3
(5) What is the output of the following program
void main(){
static int i;
clrscr();
for(++i;++i;++i) {
printf("%d ",i);
if(i==4) break;
}
getch();
}
Output: 2 4
(6) What is the output of the following program?
void main(){
int i=1;
clrscr();
for(i=0;i=-1;i=1) {
printf("%d ",i);
if(i!=1) break;
}
getch();
}
Output: -1
(7) What is the output of the following program?
void main(){
int i=1;
clrscr();
for(i=0;i=-1;i=1) {
printf("%d ",i);
if(i!=1) break;
}
getch();
}
Output: -1
(8) What is the output of the following program?
int r();
void main(){
clrscr();
for(r();r();r()) {
printf("%d ",r());
}
getch();
}
int r(){
int static num=7;
return num--;
}
Output: 5 2
(9) What is the output of the following program?
#define p(a,b) a##b
#define call(x) #x
void main(){
clrscr();
do{
int i=15,j=3;
printf("%d",p(i-+,+j));
}
while(*(call(625)+3));
//printf("%c",*("a"+1));
getch();
}
Output: 11
(11) What is the output of the following program?
int i=40;
extern int i;
void main(){
clrscr();
do{
printf("%d",i++);
}
while(5,4,3,2,1,0);
getch();
}
Output: 11
(12)
char _x_(int,...);
void main(){
char (*p)(int,...)=&_x_;
clrscr();
for(;(*p)(0,1,2,3,4); )
printf("%d",!+2);
getch();
}
char _x_(int a,...){
static i=-1;
return i+++a;
}
Output: 0
(13) What is the output of the following program?
void main(){
int i;
clrscr();
for(i=10;i<=15;i++){
while(i){
do{
printf("%d ",1);
if(i>>1)
continue;
}while(0);
break;
}
}
getch();
}
Output: 1 1 1 1 1 1
(14) What is the output of the following program?
void main(){
char c=125;
clrscr();
do
printf("%d ",c);
while(c++);
getch();
}
Output: finite numbers, because at some point c will
become 0.
(15) What is the output of the following program?
void main(){
int x=123;
int i={
printf("c" "++")
};
for(x=0;x<=i;x++){
printf("%x ",x);
}
getch();
}
Output: c++0 1 2 3
Links to this post
1 comments