rob <
r...@drrob.com> writes:
> This is my test program
>
> #include everything relevant here
> int main {
And you need ()s there and at least a "using namespace std;" unless you
are using a museum version of C++.
> int a = 0;
> float b = 1.0;
> char c = 'c';
>
> int *ptrA;
> float *ptrB;
> char *ptrC;
>
> ptrA = &a;
> ptrB = &b;
> ptrC = &c;
>
> cout << "value of a: " << a << "; address of a: " << ptrA << endl;
> cout << "vaue of b: " << b << "; address of b: " << ptrB << endl;
> cout << "value of c: " << c << "; address of c: " << ptrC << endl;
What would you like this code to do:
char *string = "Hello world\n";
cout << string;
? Can you see the problem now?
> return 0;
> }
>
>
> This program, compiled w/ gcc 9.3 on Pop_OS 20.04, does not print an
> address for c. It just prints "c"; this does show addresses for a and
> b.
>
> Why can't I show the address for the char variable c?
You can if you do this:
cout << "value of c: " << c << "; address of c: " << (void *)ptrC << endl;
--
Ben.