© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

Ex 20: What is the output?

  main()
{
 char *p;
 int *q;
 long *r;
 p=q=r=0;
 p++;
 q++;
 r++;
 printf("%p...%p...%p",p,q,r);
}
Ans:
0001...0002...0004
Explanation:

++ operator  when applied to pointers increments address according to their corresponding data-types.

Ex 21: . What is the output?

main()
  {    
char *p = “ayqm”;
printf(“%c”,++*(p++));
}
Ans:
b    

Explanation:

There is no difference between the expression ++*(p++) and ++*p++. Parenthesis just works as a visual clue for the reader to see which expression is first evaluated.

Ex 22: . What is the output?

main()
   {
            int a=2,*f1,*f2;
             f1=f2=&a;
            *f2+=*f2+=a+=2.5;
      printf("\n%d %d %d",a,*f1,*f2);
}
Ans:
16 16 16
Explanation:

f1 and f2 both refer to the same memory location a. So changes through f1 and f2 ultimately affects only the value of a.


1 >> 2 >> 3 >> 4 >> 5 >> 6 >> 7 >> 8 >> 9
SLogix Student Projects
bottom