why AA print when &ch want to print around 29:01 @tarunluthra
In pointer sectio n
@Nikhil-Aggarwal-2320066674901389
We stored ‘A’ in char ch.
cout has been defined in such a way that when we provide it a pointer to char to print , rather than printing the address , it prints the data at the that location and goes on to print till it finds a NULL character ‘\0’ .
So when wrote the statement
cout << &ch ;
Since ‘A’ was stored at ch , A got printed and then any garbage value that was stored at the memory.
The second A is a just a coincidence.
In this case , it happened at the next location after ch , it was character ‘A’ only that was stored and it was luckily ‘\0’ at the third position.
It could literally have been anything else.
It could have been “ABqwed” , “A,z…weywesdfght” or any other random string. The only thing we know for sure is that first char would be A. That’s it.
This code will give different output for everytime you run it in every different computer with every different compiler as the memory location would always be different.
If we wish to print the address instead of the data at the memory location , we need to “fool” the compiler as discussed in the video.