When you pass a pointer to std::cout it prints the value of the pointer (the address where it points).
With one exception. If you pass a char* to std::cout it assumes it is a C-String.
So if you pass a char* then it will print a string of characters upto the firdst character that is '\0' (NULL terminator).
(int*)a : 0x1e -- Why am I getting hexadecimal output, what exactly does this casting mean?
The above line converts 'a' into a pointer (without changing the value) then prints the pointer.
0x1e: This is the Hex value of 30. The 0x indicates the following are hex characters. 1e => (1 * 16) + 14 => 30
&a : 0x22ff70 -- will the address be displayed in hexadecimal format ?
The above line takes the address of 'a' (which is an int*) and print that:
(int*)&a : 0x22ff70
The above line takes the address of 'a' (which is an int*) casts that to an int* (no-op) and prints the hex value.
(char*)&a : ▲ -- as this is an address, why is it not displayed in hexadecimal ?
*(char*)&a : ▲
The above line takes the address of 'a' (which is an int*) casts this to a char* (nothing happens but a type change). You then de-reference the addrss and treat its content like a char (de-referencing a char* gives you a char). The output of this depends on how the hardware represents an integer. Because an integer is probably 4 bytes and the char is only 1 byte you are printing 1/4 of the integr (which part I am not sure without more info).
*(int *)&b : 7745 -- frankly, i donno where this value has come from, please can u explain me?
The above line is taking the address of 'b' (which is a char*) then casting this to an int* then de-referencing the pointer to get an integer (the result of this is purely random and depends on not only how the hardware represents integers but also what other values are stored in the locations after the variable b.
&b : A▲ -- why not in hexadecimal
The above is taking the address of 'b' (which is a char*) then printing it. Note that char* is a special case when printing and it is treated like a C-String. We know that 'b' is a char with the value 'A' so that is the first value printed. The value in memory write after 'b' is some random value that when printed generates a triangle on your system. It looks like the 2nd byte after the variable 'b' has the value '\0' and thus stops the printing (C-Strings are NULL ('\0') character sequences.
[/quote]