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 7 of 7.
Vinay prasad said:
1 decade ago
j is a pointer
hence,j=&i (ie,*j=3) becuase i=3
i**j=3*3=9
i**j*i=9*3=27
i**j*i+*j=27+3=30
hence,j=&i (ie,*j=3) becuase i=3
i**j=3*3=9
i**j*i=9*3=27
i**j*i+*j=27+3=30
Sai said:
1 decade ago
3*3*3+3=30
Vivek.A said:
1 decade ago
*(dereference operator) has higher precedence than the arithmetic operators. So during the evaluation of the expression
i**j*i+*j
The *j components are first evaluated and placed at their respective positions
(i.e) i*3*i+3
Then as usual arithmetics are performed to get 30
i**j*i+*j
The *j components are first evaluated and placed at their respective positions
(i.e) i*3*i+3
Then as usual arithmetics are performed to get 30
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.
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
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
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers