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.
Prakash said:
1 decade ago
Thank so far Nihar and munny
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?
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......
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)
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.
Ajay Kumar Varma said:
1 decade ago
i=3
j=&i---> *j=*(&i)---->*j=i---->*j=3
i**j*i+*j
=i*(*j)*i+(*j)
=3*3*3+3
=27+3
=30
j=&i---> *j=*(&i)---->*j=i---->*j=3
i**j*i+*j
=i*(*j)*i+(*j)
=3*3*3+3
=27+3
=30
Ashish kathait said:
1 decade ago
=i**j*i+*j {becoz *j=3)
=i**j*i+ 3
=i*3*i+ 3
=3*3*3+3
=30
=i**j*i+ 3
=i*3*i+ 3
=3*3*3+3
=30
Viji said:
1 decade ago
j=&i
& refer address of i right? How were you saying that j=3?
& refer address of i right? How were you saying that j=3?
Roopa said:
1 decade ago
Please tell the meaning of i**j*i+*j .
Rahul said:
1 decade ago
i**j*i+*j
It is executed in the following steps:
(i)*(*j)*(i)+(*j)
since *j=3 ie value at the address j, and as j stores address of i
so *j=3;
now,
(3)*(3)*(3)+(3)
=30
It is executed in the following steps:
(i)*(*j)*(i)+(*j)
since *j=3 ie value at the address j, and as j stores address of i
so *j=3;
now,
(3)*(3)*(3)+(3)
=30
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers