find the output of the following program
main()
{
int x=5, *p;
p=&x;
printf("%d",++*p);
}
Answers were Sorted based on User's Feedback
Answer / rahul khare
6
becoz it(++*p) will evaluate like this-
1)
*(p)- gives value at this address that is 5
2)
now increment ++5
that is 6.
Is This Answer Correct ? | 37 Yes | 1 No |
Answer / vignesh1988i
the answer is 6...since ++ as well as * gets the same
prority so the associativity will be right to left.. so it
will point to the value and then increment the value
Is This Answer Correct ? | 23 Yes | 3 No |
Answer / manishsoni
main()
{
int x=5, *p;
p=&x;
printf("%d",++*p);
}
it allocate as this
____ _____
x| |value p | | store &x
| 5 | | 100 |
|____| |_____|
____ _____
|100 |&x | 200 |&p p is pointer //at statement ++*p
|____| |_____|
^ ^
|________________|
and jumpt at 5 bcoz it is prefix for firstof all 5 is
increase then print
Is This Answer Correct ? | 7 Yes | 2 No |
what is difference between ++(*p) and (*p)++
17 Answers Accenture, HCL, IBM,
What is the difference b/w Structure & Union?
what are bitwise shift operators?
Explain c preprocessor?
What is the scope of an external variable in c?
How can I convert a number to a string?
differentiate built-in functions and user – defined functions.
print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 1 2 3 4 5
Is it possible to initialize a variable at the time it was declared?
How is a macro different from a function?
What is the benefit of using #define to declare a constant?
When was c language developed?