I've been doing a very basic C++ course online, and one of my first tasks is to create code that sets several variables (called a, b, c, d, e.) a value for their type, before then outputting a message with their values and addresses listed.
But when I run the code, I always get a weird address for the first variable 'a', which stores a character.
using namespace std;
char a = 'b'; //One byte, -127 to 127, or 0 t 255
int b = 5; //Four bytes, -2 billions to 2 billions
short c = 4; //Two bytes, -32768 to 32767
float d = 3.6; //Four bytes, number with up to 38 zeroes
double e = 9.9; //Eight bytes, number with up ti 308 zeroes
char *a_Address = &a;
int *b_Address = &b;
short *c_Address = &c;
float *d_Address = &d;
double *e_Address = &e;
cout << "Variable 'a' : " << a << " Variable 'a' address : " << a_Address << endl;
cout << "Variable 'b' : " << b << " Variable 'b' address : " << b_Address << endl;
cout << "Variable 'c' : " << c << " Variable 'c' address : " << c_Address << endl;
cout << "Variable 'd' : " << d << " Variable 'd' address : " << d_Address << endl;
cout << "Variable 'e' : " << e << " Variable 'e' address : " << e_Address << endl;
The message I receive from the code tends to go:
Variable 'a' : b Variable 'a' address : bت??
Variable 'b' : 5 Variable 'b' address : 0x7ffee516aab8
Variable 'c' : 4 Variable 'c' address : 0x7ffee516aab6
and so on.
The address for the variable 'a' always seems to change too - from running it a couple times I get:
Any help would be appreciated, and sorry if my writing isnt too great, this is my first time posting to the forums. Thanks in advance.