#include <iostream>
int
main(int argc, char** argv){
char a = 'a';
char* aptr = &a;
std::cout << aptr << " : " << a << std::endl;
return 0;
}
when I compile the code using g++, it gives me the output:
a : a
but when I compile using g++, it gives me the output:
a�w�� : a
what I think is that the values ahead of ‘a’ in the output of the clang compile are garbage values.
One more thing, a pointer should store the memory address if I am not wrong. Then why, in this case when I print the memory address of the char, it gives me the character itself?
I am using wsl and these are the compiler versions that I used to compile the code:
Ubuntu clang version 18.1.3 (1)
g++ (Ubuntu 13.2.0-23ubuntu4) 13.2.0
foo102111111 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.