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.

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

Rishabh said:   1 decade ago
>> Simple thumb rule.

When * and & are one after another, they cancel each other.

Example: *(&i)=&(*i)=i

Now, j=&i (given)

Therefore, *j=*(&i)=i

I hope the rest is understood.

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.

Saurabh said:   1 decade ago
i**j*i+*j dis is my exp......

so it first calculate the value of (i**j*i)
that is (i=3,*j=*(&i)=3,i=3)=3*3*3=27
then it add *j=*(&i)=3
so total equation iis=((3*3*3)+3)=30......

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

Rajesh Gautham said:   1 decade ago
It is stored in order of (*j) , +, (i) , *, (*j) , *, (i).
Here i=3, *j also 3 according to the precedence order it will execute like this.
(3) * (3) * (3) + (3) =30.

Chaitu said:   1 decade ago
It first calculate the value of (i**j*i).
That is (i=3, *j=* (&i) =3, i=3) =3*3*3=27.
Then it add *j=* (&i) =3.
So total equation is= ( (3*3*3) +3) =30.

Mukesh said:   1 decade ago
j contains address of i.

*j contains the value of i; i.e; 3

The expression then becomes i*(*j)*i+(*j)=3*3*3+3=30.

Hence the answer is 30.

Hope this helps.

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

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.


Post your comments here:

Your comments will be displayed after verification.