+ 1

Char pointer / i dont understand the output

char *var = "hello"; char *p = var; cout<<var; // outputs hello cout <<p; // outputs hello cout <<*p; // outputs h i dont understand why dont output this code addresses in memory? location? it seems to me different from int type pointets working. HELp.

29th Nov 2016, 2:32 PM
Benedek Måté Tóth
Benedek Måté Tóth - avatar
5 Answers
+ 2
if you want to see address in Memory change it to cout<<&p; this code show you address of var character.
29th Nov 2016, 3:00 PM
MerzaT
MerzaT - avatar
+ 2
write down code which i mentioned above you will see hex...
29th Nov 2016, 5:17 PM
MerzaT
MerzaT - avatar
+ 1
but how can be the address of var hello and not a hex??
29th Nov 2016, 3:49 PM
Benedek Måté Tóth
Benedek Måté Tóth - avatar
+ 1
oke, thanks, i am so confusing with this char pointer behavior.
29th Nov 2016, 5:19 PM
Benedek Måté Tóth
Benedek Måté Tóth - avatar
0
chars are treated differently in c++ than other data types.
29th Nov 2016, 4:16 PM
Mohammed Maaz
Mohammed Maaz - avatar