By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.


P: 48
Expand|Select|Wrap|Line Numbers
  1. main()
  2. {
  3. int arr[2][2][2]={10,2,3,4,5,6,7,8};
  4. int *p, *q;
  5. p=&arr[1][1][1];
  6. *q=***arr;
  7. printf("%d%d%d",*p,*q);
  8. }
for the above program my compiler gives the output as 8 10
Can you kindly explain the result
Sep 13 '10 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 8,916
Yes, at line 6 you dereference an uninitialised pointer and write to were it points invoking undefined behaviour.

Once undefined behaviour is invoked the program can do (and print) anything.
Sep 13 '10 #2

Expert 100+
P: 2,398
Line 7 has three "%d"s, but you only pass two integers.
Sep 13 '10 #3

Expert Mod 5K+
P: 9,197

Post your reply

Sign in to post your reply or Sign up for a free account.