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 2 of 7.
Dpkbohra said:
1 decade ago
int i=3, *j, k;
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
}
here,
i=3
and j= &i i.e j=3
and i**j*i+*j = i*(*j)*(i)+(*j)
= 3*(3)*(3)+(3)
= 27+3
= 30 Ans.
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
}
here,
i=3
and j= &i i.e j=3
and i**j*i+*j = i*(*j)*(i)+(*j)
= 3*(3)*(3)+(3)
= 27+3
= 30 Ans.
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)
*(indirection operator) has more precedene over + and *(multiply)
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......
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......
Femi said:
1 decade ago
j=&i; it means j will have the address of i
But now will be having the value of i, how it comes?
But now will be having the value of i, how it comes?
Prakash said:
1 decade ago
Thank so far Nihar and munny
Divya said:
1 decade ago
Thank you munna simple and best explanation
Deepika said:
1 decade ago
Thanks Nihar
Siddharth said:
1 decade ago
i**J = 3*3 = 9
i**j*i = 9*3 = 27
i**j*i+*j = 27+3 = 30.
i**j*i = 9*3 = 27
i**j*i+*j = 27+3 = 30.
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 //////
The compiler takes as i * *j * i + *j So
3 * 3 * 3 + 3 = 30 //////
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
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
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers