C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 2)
2.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int i=3, *j, k;
    j = &i;
    printf("%d\n", i**j*i+*j);
    return 0;
}
30
27
9
3
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
65 comments Page 4 of 7.

Raz said:   1 decade ago
i=3;
*j=3;

So given statement is read by compiler as.
[(i)*(*j)*(i)+(*j)]
[(3)*(3)*(3)+(3)]
[27+3]
[30]

Ajay Kumar Varma said:   1 decade ago
i=3
j=&i---> *j=*(&i)---->*j=i---->*j=3

i**j*i+*j
=i*(*j)*i+(*j)
=3*3*3+3
=27+3
=30

Femi said:   1 decade ago
j=&i; it means j will have the address of i

But now will be having the value of i, how it comes?

Vinay prasad said:   1 decade ago
j is a pointer
hence,j=&i (ie,*j=3) becuase i=3
i**j=3*3=9
i**j*i=9*3=27
i**j*i+*j=27+3=30

Adi said:   3 years ago
Why &a is considered its value if &a means address of a on ram?

Please explain me.

Binny said:   1 decade ago
Well done it was a trick as i, i is not a pointer so how we can interpret 2nd* as pointer.

John Jose said:   1 decade ago
j=&i implies *j=i;

*j=3.
i**j=3*3 = 9.
i**j*i=9*3 = 27.
i**j*i+*j = 27+3 = 30.

Viji said:   1 decade ago
j=&i

& refer address of i right? How were you saying that j=3?

Vijay s Rao said:   7 years ago
j=&i implies *j=i;
*j=3
i**j=3*3=9
i**j*i=9*3=27
i**j*i+*j=27+3=30.

Zdd said:   8 years ago
i=3;
j=&i i.e. *j==i==3
i**j*i+*j i.e. i*(*j)*i+(*j)==3*3*3+3==30.


Post your comments here:

Your comments will be displayed after verification.