V
V
Vadim Remin2016-07-07 09:09:58
C++ / C#
Vadim Remin, 2016-07-07 09:09:58

Pointers in C++: what is "x{"?

Good afternoon,
below is the code from which the essence of the question is clear. Thanks in advance!

char r = 'R';
char *rPtr = &r;

cout << r << endl; // R
cout << &r << endl; // R{   - что это значит? по идее тут должен быть адрес ячейки памяти для хранения char 'R'
cout << rPtr << endl; // R{
cout << *rPtr << endl; // R
cout << &rPtr << endl; // 0x7ffd015fd1e0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2016-07-07
@dkudrin1

The matter is that for char* the special mechanism of an output in a stream works. This pointer is not treated as an address, but as a C string. The first character of the string will, of course, be R. And then it goes through memory and outputs all the bytes in a row until it finds 0.
Since after char (1 byte) comes char* (8 bytes), we will have to create seven alignment bytes (judging by pointer length, we are on x64). In these seven bytes, a curly brace, zero, and it is not clear what were found.
Put instead of char int - everything will be as you thought. The int* pointer is output without any interpretation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question