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.

Tanu said:   1 decade ago
Arrange the expression as : (i*(*j)*i)+(*j))
Now, i = 3
*j = (Value at Address of) j = 3

So, expression comes out to be: (3*3*3)+(3)) = 30.

Srinivas said:   1 decade ago
#include<stdio.h>

int main()
{
int i=3, *j, k;
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
}
In this program,we are storing the address of the value 3 in j.And *j is pointing to the same value 3.In the printing statement ,it will take *j=3,and i=3.so (i)*(*j)*i+*j
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.

Satti(iiit) said:   1 decade ago
Very nice munny. I am getting your explanation.

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.

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.

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.

Dipankar Pramanik said:   1 decade ago
Here i=3 and *j=3.
So i *(multiplication) *j=3x3=9.

Then 9 * (mul) i=9x3=27.
At last 27 + (add) *j=27+3=30.

Spurthi said:   1 decade ago
Here i**j=3*3=9.

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

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

Sudhakar said:   1 decade ago
I have one more doubt.

i**j*i+*j=i*(*j)*(i)+(*j)

*j=i=3
Then ((3*3)*3)+3=30
Upto this it will be k.

Add 1 more *i to the above given means
i**j*i+*j*i=should be 30*3=90.

But the output is showing as 36 reason please?


Post your comments here:

Your comments will be displayed after verification.