Похожие чаты

So I tried this: int arr[3];

arr[0] = 1;
arr[2] = 2;

std::cout << *(arr + 1) << std::endl;

This is the output i got:
677446592

Since data in array are contiguous, why didn't I get 2?

9 ответов

7 просмотров

your data is contiguos but the [1] element has no value set

Because you didn't set second element of an array

🖖- Автор вопроса
🖖
oh so space for it reserved?

its like if you try to do a print for int a; without setting the data

🖖- Автор вопроса
Kirill 🚜
Yes

...so what am I shifting when I do "arr[1] =2", that makes the insertion time O(n)?

🖖
...so what am I shifting when I do "arr[1] =2", th...

you are not inserting anything, you are setting the value of an element

🖖- Автор вопроса

This is undefined behavior, there is called stack redzone. It may contain garbage value from previous function. You are printing this garbage value.

Похожие вопросы

Обсуждают сегодня

Вопрос по диагностике ошибок (я знаю в чем, в данном конкретном примере, я знаю, как исправить, пример модельный, понятно, что в реальности бывает намного запутаннее). module...
ⰄⰎⰋⰐⰐⰑⰛⰤⰧⰧⰩⰄ ⰊⰑⰁⰓⰡⰛⰦⰕⰫ
10
Тут кста кто-нибудь NeoVim использует?
Simple Sorcerer
13
А чем вам питонисты не угодили?😂
.
79
Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
52
New Hedera drama. Is Hashinals on chain or not on chain?
Perfect Ability
15
Can someone explain me the difference of the stated quote on Quants homepage between R3 and Quant? „R3 brings its ability to deliver complex pioneering projects for regulate...
Carlson
2
Asus, норм фирма для ноутов?
Артем Записной
20
guys, why is it taking days for my node to sync? is this normal?
Big Chiano
10
А дальше что?.. Записать в файл, потом в Код?.. И потом разбирать как-то?..
Хаскель Моисеевич Гопник
14
Ребят немного глупый вопрос, но я правильно понимаю что неполнота по геделю означает наличие парадокса?
Smith
9
Карта сайта