Weird value from finding a variables address

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main()
{
    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:
b????
bؚZ??
b؊???

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.
The operator<< of the stream interprets a_Address as c-string and trys to output that string.

To get the pointer better use void:

void *a_Address = &a;
If you use printf the output prints the correct result: http://www.cplusplus.com/forum/beginner/1428/
Thanks guys, I tried 'void' and it worked. Still learning the vocabulary for C++, and the course I'm using hasn't dipped in far yet.

Cheers!
Topic archived. No new replies allowed.