CFAQ

From C4swimmers

1.What would be the output of the following

  1. include<stdio.h>

main() { extern int a; printf("%d",a); }

int a=20;

ans:20


2.what o/p

main() { int a[5]={2,3} printf("\ %d %d %d",a[2],a[3],a[4]); }

ans:0 0 0

3.main() { int i=-3,j=2,k=0,m;

  m=++i&&++j||++k;
 printf("\

%d %d %d",i,j,k,m);

ans:-2,3,0,1

4.main() { int a,b; a=sumdig(123); b=sumdig(123); printf("%d %d",a,b);

}

sumdig(int n) {

 static int s=0;

int d; if(n!=0) { d=n%10; n=(n-d)/10; s=s+d; sundig(n);

}

else

return(s); }

ans:6,12

5.#defineCUBE(x) (x*x*x) main() {

 int a,b=3;
 a=CUBE(b++);

printf("\ %d %d",a,b);

}

ans:27,6

6.main() { const int x=get(); printf("%d",x); }

get() { ! return(20);

}

ans:20

7.afunction has a prototype void f1(int **x)

how will you call the function

8.point out error

main() { int i=1; for(;;) { printf("%d",i++);

  if(i>10)
  break;

}

ans:No error

9.can the following code be executed int main() {

 char stra[10]="Compile",strb[10];
 my_strcpy(strb,stra);
 puts(strb);

}

char *my_strcpy(char *destination,char *source) {

  char *p=destination;
  while(*source!='\\0')
  {
    *p++=*source++;
 }
  • p='\\0';



good luck from rock......... return destination;

}

ans:compilation will only give a warning but will proceed to execute and will display "compile"

10.o/p

  1. include<stdio.h>

main() { char str[5]="fast"; static char *ptr_to_array=str; printf("%s",ptr_to_aray); } ans:compilation will only give a warning but will proceed to execute and diaplay "fast"

11. main() { int num,*p; num=5; p=&num;

  • p++;

printf("%d",*p); }

ans:Junk value

12. main() { int a[3]={2,3,4}; cahr *p; p=a;p=(char*)((int*)p+1); printf("%d",p); } ans:3

13. main() { int i=10; fn(i); printf("%d",i); }

fn(int i) { return ++i; }

ans:10

14.what will be the value of i&jafter this loop for(i=0,j=0;i<5,j<25;i++,j++)


15. main() { int i,j; i=10; j=sizeof(++i); printf("%d",i);

}

ans:10

16. main() { int i=7; printf("%d",i++ * i++);

}

ans:49

17. main() { cahr *p,*f(); p=f(); printf(""f()returns:%s",p); }

char *f() { char result[80]; strcpy(result,"anything will do"); return(result); }

18. ! main() {printf("jamboo");

main(); } ans:till the stack doesnotoverflow

19.

main() { int a=10,j; j=fn(a); switch(j) { case 30:printf("the value is 30");

          break;

case 50:printf("the value is 50");

          break;

default:printf("the value is not 30 or 50");

}

fn(int a) { return(++a); }

ans:tHe value is not 30 or 50

20. main() { struct emp {

 char name[20];
 int age;
 float sal;

}; struct emp e={"Tiger"}; printf("%d %f",e.age,e.sal); }

ans: 0 0.0000000

Personal tools