Predict the output or error(s) for the following:
1. struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi,jkl;
int x=100;
abc.i=0;abc.prev=&jkl;
abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
}
2. struct point
{
int x;
int y;
};
struct point origin,*pp;
main()
{
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
3. main()
{
int i=_l_abc(10);
printf("%d\n",--i);
}
int _l_abc(int i)
{
return(i++);
}
4. main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
}
5. main()
{
char c=' ',x,convert(z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c);
printf("%c",x);
}
convert(z)
{
return z-32;
}
6. main(int argc, char **argv)
{
printf("enter the character");
getchar();
sum(argv[1],argv[2]);
}
sum(num1,num2)
int num1,num2;
{
return num1+num2;
}
7. # include
int one_d[]={1,2,3};
main()
{
int *ptr;
ptr=one_d;
ptr+=3;
printf("%d",*ptr);
}
8. # include
aaa() {
printf("hi");
}
bbb(){
printf("hello");
}
ccc(){
printf("TechPreparation.com");
}
main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}
9. #include
main()
{
FILE *ptr;
char i;
ptr=fopen("zzz.c","r");
while((i=fgetch(ptr))!=EOF)
printf("%c",i);
}
10. main()
{
int i =0;j=0;
if(i && j++)
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}
11. main()
{
int i;
i = abc();
printf("%d",i);
}
abc()
{
_AX = 1000;
}
12. int i;
main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--",t--);
}
// If the inputs are 0,1,2,3 find the o/p
13. main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello");
}
14. main(){
unsigned int i;
for(i=1;i>-2;i--)
printf("c aptitude");
}
15. In the following pgm add a stmt in the function fun such that the
address of
'a' gets stored in 'j'.
main(){
int * j;
void fun(int **);
fun(&j);
}
void fun(int **k) {
int a =0;
/* add a stmt here*/
}
16. What are the following notations of defining functions known as?
i. int abc(int a,float b)
{
/* some code */
}
ii. int abc(a,b)
int a; float b;
{
/* some code*/
}
Predict the output or error(s) for the following:
16. main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
}
17. main(){
char a[100];
a[0]='a';a[1]]='b';a[2]='c';a[4]='d';
abc(a);
}
abc(char a[]){
a++;
printf("%c",*a);
a++;
printf("%c",*a);
}
18. func(a,b)
int a,b;
{
return( a= (a==b) );
}
main()
{
int process(),func();
printf("The value of process is %d !\n ",process(func,3,6));
}
process(pf,val1,val2)
int (*pf) ();
int val1,val2;
{
return((*pf) (val1,val2));
}
19. void main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
20. void main()
{
int k=ret(sizeof(float));
printf("\n here value is %d",++k);
}
int ret(int ret)
{
ret += 2.5;
return(ret);
}
21. void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("here in 3 %d\n",++i);
}
22. void main()
{
unsigned giveit=-1;
int gotit;
printf("%u ",++giveit);
printf("%u \n",gotit=--giveit);
}
23. void main()
{
int i;
char a[]="\0";
if(printf("%s\n",a))
printf("Ok here \n");
else
printf("Forget it\n");
}
Predict the output or error(s) for the following:
24. void main()
{
void *v;
int integer=2;
int *i=&integer;
v=i;
printf("%d",(int*)*v);
}
25. void main()
{
int i=i++,j=j++,k=k++;
printf(“%d%d%d”,i,j,k);
}
26. void main()
{
static int i=i++, j=j++, k=k++;
printf(“i = %d j = %d k = %d”, i, j, k);
}
27. void main()
{
while(1){
if(printf("%d",printf("%d")))
break;
else
continue;
}
}
28. main()
{
unsigned int i=10;
while(i-->=0)
printf("%u ",i);
}
29. #include
main()
{
int x,y=2,z,a;
if(x=y%2) z=2;
a=2;
printf("%d %d ",z,x);
}
30. main()
{
int a[10];
printf("%d",*a+1-*a+3);
}
31. #define prod(a,b) a*b
main()
{
int x=3,y=4;
printf("%d",prod(x+2,y-1));
}
32. main()
{
unsigned int i=65000;
while(i++!=0);
printf("%d",i);
}
Predict the output or error(s) for the following:
33. main()
{
int i=0;
while(+(+i--)!=0)
i-=i++;
printf("%d",i);
}
34. main()
{
float f=5,g=10;
enum{i=10,j=20,k=50};
printf("%d\n",++k);
printf("%f\n",f<<2);
printf("%lf\n",f%g);
printf("%lf\n",fmod(f,g));
}
35. main()
{
int i=10;
void pascal f(int,int,int);
f(i++,i++,i++);
printf(" %d",i);
}
void pascal f(integer :i,integer:j,integer :k)
{
write(i,j,k);
}
36. void pascal f(int i,int j,int k)
{
printf(“%d %d %d”,i, j, k);
}
void cdecl f(int i,int j,int k)
{
printf(“%d %d %d”,i, j, k);
}
main()
{
int i=10;
f(i++,i++,i++);
printf(" %d\n",i);
i=10;
f(i++,i++,i++);
printf(" %d",i);
}
37. What is the output of the program given below
main()
{
signed char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}
38. main()
{
unsigned char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}
39. main()
{
char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}
40. Is the following statement a declaration/definition. Find what does it
mean?
int (*x)[10];
41. What is the output for the program given below
typedef enum errorType{warning, error, exception,}error;
main()
{
error g1;
g1=1;
printf("%d",g1);
}
42. typedef struct error{int warning, error, exception;}error;
main()
{
error g1;
g1.error =1;
printf("%d",g1.error);
}
Predict the output or error(s) for the following:
43. #ifdef something
int some=0;
#endif
main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}
44. #if something == 0
int some=0;
#endif
main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}
45. What is the output for the following program
main()
{
int arr2D[3][3];
printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) );
}
46. void main()
{
if(~0 == (unsigned int)-1)
printf(“You can answer this if you know how values are represented in
memory”);
}
47. int swap(int *a,int *b)
{
*a=*a+*b;*b=*a-*b;*a=*a-*b;
}
main()
{
int x=10,y=20;
swap(&x,&y);
printf("x= %d y = %d\n",x,y);
}
48. main()
{
char *p = “ayqm”;
printf(“%c”,++*(p++));
}
49. main()
{
int i=5;
printf("%d",++i++);
}
50. main()
{
char *p = “ayqm”;
char c;
c = ++*p++;
printf(“%c”,c);
}
51.
int aaa() {printf(“Hi”);}
int bbb(){printf(“hello”);}
iny ccc(){printf(“bye”);}
main()
{
int ( * ptr[3]) ();
ptr[0] = aaa;
ptr[1] = bbb;
ptr[2] =ccc;
ptr[2]();
}
52.
main()
{
int i=5;
printf(“%d”,i=++i ==6);
}