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

Aakash said:   1 decade ago
Here i=3
j=&i;
so *j=3

Now the expression:

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

Since *has higher precedence over +

Priya said:   1 decade ago
i**j*i+*j
evaluation is done according to the priority.

(like int i,j;
int h=i*j/j;
here * will done then / will process.)


we have 2 different i*h(means multiple),*j (means value of pointer at address)

*j has high priority than multiple.


i**j*i+*j
step1 i*3*i+*j
step2 i*3*i+3
step3 3*3*i+3=9*i+3
step4 9*3+3=27+3
step5 30

Zohra said:   1 decade ago
Well explained. Munny and Nihar. Thank You.

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]

Preeti said:   1 decade ago
Thanx Ajay Kumar Varma..explanation was great!!

Basant said:   1 decade ago
*j means holding the adreess of i=3
we know that i =3 that means some address will be of that variable
so that addrs hold by j
and J=&i mns address of i
then
*j=means j holding 3
*j=3
3*j(=3)*i(=3)+*j(=3)=30

Abdullah said:   1 decade ago
in here statement is i**j*i+*j

The compiler takes as i * *j * i + *j So
3 * 3 * 3 + 3 = 30 //////

Siddharth said:   1 decade ago
i**J = 3*3 = 9

i**j*i = 9*3 = 27

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

Deepika said:   1 decade ago
Thanks Nihar

Divya said:   1 decade ago
Thank you munna simple and best explanation


Post your comments here:

Your comments will be displayed after verification.