Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #80712
| From | "Fred. Zwarts" <F.Zwarts@KVI.nl> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Trying to understand pointers. Why does this give unexpected results? |
| Date | 2021-07-15 09:45 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <scop36$1k4k$1@gioia.aioe.org> (permalink) |
| References | <5og1egt5kc9m17k8ndg5qiv9djdtk20844@4ax.com> <87bl7jdty0.fsf@bsb.me.uk> <93n1eg56unidh0g7fine23uhtdtmos2lvc@4ax.com> <sbqn1q$1t20$1@gioia.aioe.org> |
Op 04.jul..2021 om 00:04 schreef Real Troll:
> On 03/07/2021 22:54, rob wrote:
>> Thanks, that helps me.
>>
>>
>>
>>
>>>> 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;
>
> You could also do something like this:
>
>> #include <iostream>
>>
>> using namespace std;
>>
>> int main()
>> {
>> 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;
Doesn't that print the address of ptrC, instead of the address of c?
>>
>> return 0;
>> }
>
>
>
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Trying to understand pointers. Why does this give unexpected results? rob <rob@drrob.com> - 2021-07-03 16:12 -0400
Re: Trying to understand pointers. Why does this give unexpected results? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-03 21:27 +0100
Re: Trying to understand pointers. Why does this give unexpected results? rob <rob@drrob.com> - 2021-07-03 17:54 -0400
Re: Trying to understand pointers. Why does this give unexpected results? Real Troll <real.troll@trolls.com> - 2021-07-03 22:04 +0000
Re: Trying to understand pointers. Why does this give unexpected results? "Fred. Zwarts" <F.Zwarts@KVI.nl> - 2021-07-15 09:45 +0200
Re: Trying to understand pointers. Why does this give unexpected results? Juha Nieminen <nospam@thanks.invalid> - 2021-07-08 08:17 +0000
csiph-web