Hello, I am getting unexpected output when using & operator with char variable. Why is it so ?
Doubt in my code
Hey @yashsharma4304
when u print &x with char datatype then instead of printing address it print the string until a \n is encountered
char x ='A';
char y='\0'; //this is allocated directly after x in background (not always true)
cout<< &x <<endl;
when u do this u will see only A getting printed because null is present immediately after A
Also see this
char x ='A';
char z='B';
char y='\0';
cout<< &x <<endl;
As I told u it will print until a NULL char is encounterd
So there must be a null char present there already in memory while he was making this lecture
So do you mean that it is recommended to put a null character by your own. It may be present or may not be present in the memory. And while recording lecture he may get this weird output as he has not put null at the end ?
Yes
I never used this way for printing , this is just for knowledge
Ok thanks.
Ok because we donβt use address of operator with char variable.
Yes ,you will only be using & with other data types
ok. Thank you for your guide.