This is a discussion on Help in Output within the C and C++ forums, part of the Programming Talk category; My friend questioned me the output of the below program #include <stdio.h> main() { int a[] = { 1, 4, ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Help in Output
My friend questioned me the output of the below program
#include <stdio.h> main() { int a[] = { 1, 4, 8, 5, 1, 4 }; int *s,b; s = a + 4; b = s - a; printf("%d",b); } I told the output as 8.But he told me its wrong and asked me to try. Kindly someone help me to solve this problem. |
|
|||
|
Yes as your friend said your answer was wrong. The output is 4.Its simple. Consider the base address or starting address of a as 1000. So you would have 1000+4=1004 stored in s and again
b=s-a gives b=1004-1000=4 and b is outputted which gives the output as 4. |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Different Output | cyrus | C and C++ | 3 | 06-02-2007 02:04 AM |
| Puzzled on Output | Adrian | C and C++ | 2 | 05-24-2007 04:30 PM |
| To get Output | Rahulbatra | C and C++ | 1 | 05-10-2007 09:23 AM |
| Amazing Output | cyrus | C and C++ | 1 | 05-08-2007 04:37 PM |
| C Programming - Managing Input and Output Operations | JobHelper | Career Advice | 0 | 04-15-2006 08:30 AM |