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 2 of 7.

ROG said:   7 years ago
First;

j=&i implies *j=I,
Then;
*j=3,
i**j = 3*3=9,
i**j*i= 9*3= 27,
i**j*i+*j = 27+3 = 30.

Zdd said:   7 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.

Eswari reddy said:   8 years ago
i=3,*j,k;
j=&i; then
j=&3 means *j=3
i**j*i+*j=3*3*3+3=27 +3=30.

Sunil Phad said:   9 years ago
j=&i,

So, *j=i;
*j=3
i**j
3*3=9
i**j*i
9*3=27
i**j*i+*j
27+3 = 30.

Shreyan said:   9 years ago
Thanks, @Munny. Your method seemed simple and short :).

Subroto Biswas said:   1 decade ago
It's simple:

= 3*3*3+3.

So, 9*3+3 = 27+3.

Finally, 30.

Hemanth Kumar M said:   1 decade ago
*j -> 3.
i = 3.

Therefore 3*3*3+3.

Due to associativity from l to f.

*-> has highest priority.

+-> next priority.

Hence 9*3+3 = 27+3.

->30.

Neha said:   1 decade ago
Ok but why do we try out and make j=3.

Nap said:   1 decade ago
Answer = 30 because,
i**j*i+*j = (3*3*3+3).
Where i=3 and *j=3.

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.


Post your comments here:

Your comments will be displayed after verification.