if I store &ch in another variable and then print it…would it be work or not ?
Datatype of &ch
Hey Gaurav, yes it will definitely work but just keep in mind that you are storing &ch i.e. address of variable ch in another variable, so that another variable must be pointer. For eg. you can do it like this :
int a;
a=10;
int *b = &a;
cout<<a<<" "<<b;
storing the address of a character variable in an character pointer and than printing the content of this pointer bucket will give address stored in that bucket or the value of character variable ?
if it gives value of character variable then how ?
Hey Gaurav, the code snippet given below will print the character ‘a’ because in c++ if you print a pointer to a character then it will print the character stored at that address (stored in the pointer) instead of the address unlike other data types. That’s because there is a special overload in operator<< in C++, so when you are taking the address of ch, C++ interprets that as a C string, and tries to print a character sequence instead of its address.
char ch = 'a';
char* add = &ch;
cout<<add;
thank you so much…