OpenStudy (anonymous):

#include #include main() {int x1 = 10; int *x2, **x3, ***x4; x2 = &x1; x3 = &x2; x4 = &x3; printf("%d%d%d%d", (x1==10), (*x2==10),( *x3==10), (***x4==10) ); return 0; } out put : 1101

3 years ago
OpenStudy (mandre):

And your question is?

3 years ago
OpenStudy (anonymous):

I am sorry @Mandre my question is why and how did we get this output?

3 years ago
OpenStudy (mandre):

x1 = 10 so x1==10 will return 1, i.e. it is true that x1 = 10. x2 is a pointer which points to x1. The dereferencing operator * tells us to give us the contents of the address pointed to by x2. x2 is pointing towards x1 so *x2 = 10, therefore x2==10 equals 1 or true. Look at how the variables are declared. x1, *x2 and ***x4 is shown correctly, whereas **x3 is not, i.e they are all true except for *x3 == 10, as *x3 = [address of x1]. **x3 = [contents of address of x1], i.e. **x3 = 10. I'm still learning C++ myself and this dereferencing regularly trips me up so I hope I made it clear *ahem*.

3 years ago
OpenStudy (anonymous):

@Mandre got it thanks :). where are u learning c++ from?

3 years ago
OpenStudy (mandre):

My pleasure. I use learncpp.com and of course my textbook, Data Structures using C++ by DS Malik.

3 years ago
Similar Questions: