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

Result of pointer arithmetic

P: 1
)what is output for the following program.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. main()
  4.  
  5. {
  6.  
  7. int *p,*q,i;
  8.  
  9. p=(int *)100;
  10.  
  11. q=(int *)200;
  12.  
  13. i=q-p;
  14.  
  15. printf("%d",i);
  16.  
  17. }
Sep 6 '10 #1
Share this Question
Share on Google+
2 Replies


100+
P: 687
Do you have a compiler to check it yourself? If it outputs 50 or 25, what does it mean?
Sep 6 '10 #2

ashitpro
Expert 100+
P: 542
on platform where integer is of 4 bytes you will get 25 as an answer..

In other case where integer size is 2 bytes, answer will be 50..

Its self explanatory....
Sep 6 '10 #3

Post your reply

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