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 4 of 7.
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.
Ksk said:
4 years ago
Thank you for explaining this @Rahul.
Adi said:
3 years ago
Why &a is considered its value if &a means address of a on ram?
Please explain me.
Please explain me.
Deepika said:
1 decade ago
Thanks Nihar
Munny said:
2 decades 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
Nihar said:
1 decade ago
i**j*i+*j
Here the * symol before j is pointer value of j and * symbol before i and after i is for multiplication.
So the execution will be
i**J = 3*3 = 9
i**j*i = 9*3 = 27
i**j*i+*j = 27+3 = 30.
Here the * symol before j is pointer value of j and * symbol before i and after i is for multiplication.
So the execution will be
i**J = 3*3 = 9
i**j*i = 9*3 = 27
i**j*i+*j = 27+3 = 30.
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
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
Rakesh said:
1 decade ago
Munny and nihar gave correct explanation.
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
Roopa said:
1 decade ago
Please tell the meaning of i**j*i+*j .
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers