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 3 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.

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 +

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

Riya Goel said:   1 decade ago
It is done by the help of precedence and associativity table.
*(indirection operator) has more precedene over + and *(multiply)

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.

Shiv said:   6 years ago
Since,
i=3.
*j=content at *j means value of X.
means *j=3.
Replace i with 3 and *j also with 3.
Then, 3*3*3+3=27+3 i.e. 30.
(3)

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 //////

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.

GrenFo said:   2 years ago
@All.
Here is the coding;

simplefied ->
// i * *j * i + *j
// i * (*j) * i + (*j)
// 3 * 3 * 3 + 3
// 30
(24)

Soumen Maity said:   1 decade ago
In printf() the operation should be right to left. I don't why you guys are doing left to right operation.


Post your comments here:

Your comments will be displayed after verification.