
- Forum
- Programming Talk
- C and C++
- Help in Output
Help in Output
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, ...
-
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.

Reply With Quote





