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;
}
Discussion:
65 comments Page 6 of 7.
Shreyan said:
9 years ago
Thanks, @Munny. Your method seemed simple and short :).
Sunil Phad said:
9 years ago
j=&i,
So, *j=i;
*j=3
i**j
3*3=9
i**j*i
9*3=27
i**j*i+*j
27+3 = 30.
So, *j=i;
*j=3
i**j
3*3=9
i**j*i
9*3=27
i**j*i+*j
27+3 = 30.
Eswari reddy said:
8 years ago
i=3,*j,k;
j=&i; then
j=&3 means *j=3
i**j*i+*j=3*3*3+3=27 +3=30.
j=&i; then
j=&3 means *j=3
i**j*i+*j=3*3*3+3=27 +3=30.
Zdd said:
8 years ago
i=3;
j=&i i.e. *j==i==3
i**j*i+*j i.e. i*(*j)*i+(*j)==3*3*3+3==30.
j=&i i.e. *j==i==3
i**j*i+*j i.e. i*(*j)*i+(*j)==3*3*3+3==30.
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.
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.
Navas v said:
7 years ago
Here using precedence of operator first evaluate * (dereferencing operator) associativity from right to left.
So expression become i*(*J)*i+(*j) ->> i*(3)*i+(3).
Then precedence goes to * (multiplication operator) and their associativity from left to right
so it become ((i*3)*i)+3--> 3*3*3+3=27.
So expression become i*(*J)*i+(*j) ->> i*(3)*i+(3).
Then precedence goes to * (multiplication operator) and their associativity from left to right
so it become ((i*3)*i)+3--> 3*3*3+3=27.
Vijay s Rao said:
7 years 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.
*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.
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)
Ksk said:
4 years ago
Thank you for explaining this @Rahul.
Jp said:
4 years ago
@ALL.
Just simplify it;
i*(*j)*i+(*j).
3*(3)*3+3.
Just simplify it;
i*(*j)*i+(*j).
3*(3)*3+3.
(3)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers