Sunday 18 August 2013

Different content of &a

Different content of &a

Im looking for a better understanding of the following 3 examples.
This is my questions to the following code examples.
Ex. 1. Example makes sense, it outputs the adress of which the int a is
stored.
Ex. 2. Makes a little less sense for. I think it is because the char
itself points to the char?
Ex. 3. Confuses me. In the output the first char output is always the on
stored in the char. But what are the appending chars and why do they
appear after saving &a to a char pointer?
Lastly how do i output the adress of the memory location of where a char
variable is saved?
Ex. 1
main(void)
{
int a = 1;
cout << &a;
}
Outputs the memory adress ex. 0x7fff4241b7b4
Ex 2.
main(void)
{
char a = 'a';
cout << &a;
}
Outputs the char a. ex. a
Ex. 3.
main(void)
{
char a = 'a';
char *b = &a;
cout << &a;
}
Outputs a&#65533;&#65533;:&#65533;&#65533;

No comments:

Post a Comment