Thursday, November 19, 2009

C/C++ teaser

This is not very difficult. But just have a look.

1. Predict the outcome
#include < stdio.h >
main()
{
int a=0;
printf("%s",a);
}

2. Predict the outcome
#include < stdio.h >
main()
{
int arr[]={2,3,4,5,6};
int *iptr=arr;
iptr++;
printf("%d",*(iptr+i));
arr++;
printf("%d",*(arr+i));
}


3. Predict the outcome
#include < stdio.h >
main()
{
int arr[]={2,3,4,5,6};
int *iptr=arr;
int i=0;
printf("%d,%d%d,%d",*(iptr+i),i[arr],arr[i],*(arr+i));
}


Please answer the questions as comments. The answers will be posted soon.

Thanks
Layman

2 comments:

  1. 1.null( I think)
    3. 2,22,2.. did u miss the comma b/w 2nd and third?

    ReplyDelete
  2. Common, thats a good effort. I would want more replies......

    ReplyDelete