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

Shunmu said:   2 decades ago
i**j*i+*j
above line executed in following steps
1>i**j
3**3=9
2>i**j*i
9*3=27(9 from the previous step)
3>i**j*i+*j
27+*j=27+*j=27+3=30

Munny said:   2 decades 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

Nihar said:   1 decade ago
i**j*i+*j

Here the * symol before j is pointer value of j and * symbol before i and after i is for multiplication.

So the execution will be

i**J = 3*3 = 9

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

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

Sona said:   1 decade ago
i**j*i+*j
above line executed in following steps
i*(*j)*i+(*j)
now since i=*j=3
therefore
i**j*i+*j=i*(*j)*i+(*j)=3*(3)*3+(3)=30

Rakesh said:   1 decade ago
Munny and nihar gave correct explanation.

Rahul said:   1 decade ago
i**j*i+*j
It is executed in the following steps:
(i)*(*j)*(i)+(*j)

since *j=3 ie value at the address j, and as j stores address of i
so *j=3;

now,
(3)*(3)*(3)+(3)
=30

Roopa said:   1 decade ago
Please tell the meaning of i**j*i+*j .

Viji said:   1 decade ago
j=&i

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

Ashish kathait said:   1 decade ago
=i**j*i+*j {becoz *j=3)
=i**j*i+ 3
=i*3*i+ 3
=3*3*3+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


Post your comments here:

Your comments will be displayed after verification.