printf(MEMORY) | How to print memory to the console

  Рет қаралды 9,594

CodeVault

CodeVault

Күн бұрын

Пікірлер: 19
@undefined_exception_0
@undefined_exception_0 3 жыл бұрын
Thank You Sir , your content is rare and precious on KZbin!
@mehmetcivan
@mehmetcivan 2 жыл бұрын
best channel i've watched on youtube. thanks
@shadmanahmed271
@shadmanahmed271 Жыл бұрын
Best tutor for c. Should have made a course and publish on udemy/coursera
@CodeVault
@CodeVault Жыл бұрын
There are a few courses on udemy, but I prefer hosting them on KZbin or my website instead
@chenwu9788
@chenwu9788 2 жыл бұрын
Can you explain why converts &t to unsigned char*, not unsigned short*, or just char*?
@CodeVault
@CodeVault 2 жыл бұрын
It's unsigned because we're reading each byte so the first bit doesn't represent the sign of some number. It's char because sizeof(char) == 1 byte so, if you do any pointer operations it will only multiply the operation by 1 (which is the same as not multiplying)... For example: int someVariable; // suppose the address of it is 1000000 unsigned char* p1 = &someVariable; unsigned short* p2 = &someVariable; // Here both p1 and p2 point to the same address p1 = p1 + 1; // p1 is now pointing at 1000001 p2 = p2 + 1; // p2 is now pointing at 1000002 So, with p2, I cannot make it point to 1000001 by just addition (I'd have to cast it to a char*)
@davidali133
@davidali133 Жыл бұрын
I kinda expected you to explain typedef struct __attribute__((__packed__)) { int test; char k; char str[10]; int* p; short sh; } Thing; Anyways, I love your series! Keep up the good work!
@CodeVault
@CodeVault Жыл бұрын
There's a video on this but it's partially wrong, I will soon be correcting it
@景貴張
@景貴張 2 жыл бұрын
Hi, I have a question. In line 30, you have made “data” become the address of each byte, and print it in line 31. Why does it print the value store in the address but not address itself? Thank you.
@CodeVault
@CodeVault 2 жыл бұрын
data stores the value of each byte, not the address. data = *(((unsigned char*) &t) + i); That first character (the *) dereferences the whole structure and returns the value at the address. Thus printf simply prints the value stored at that address
@景貴張
@景貴張 2 жыл бұрын
Think you so much, I just missed the “ * “ outside the bracket.
@nikhilpradhan7404
@nikhilpradhan7404 2 жыл бұрын
address is not store there. * is used to dereference the value stored in the address so the value is store in data
@noweare1
@noweare1 11 ай бұрын
I think one of the most confusing things about c is they use to define a pointer variable using * and also use * as a dereference operator.
@CJKuo
@CJKuo Жыл бұрын
This is so disgusting,thank you to show how the memory works
@throatwobblermangrove7508
@throatwobblermangrove7508 2 жыл бұрын
Awesome as always. Are there any plans to cover assembler?
@CodeVault
@CodeVault 2 жыл бұрын
If it's requested a lot I might dive into a bit of assembly
@deltaoui
@deltaoui 9 ай бұрын
Nice tutorial, just one thing : I think you went too quickly on explaining the extra bytes with 00 after the last attribute of the struct. I am not sure I understand why it was added. Is it related to the fact that we always go in (8, 16, 32, 64, 128,..) in memory and you can't have something in between ?
@CodeVault
@CodeVault 8 ай бұрын
It's to do with memory alignment. Basically each struct member is always going to be allocated to a memory address divisible by its size. This improves the speed at which the CPU caches the memory (amongst other things)
@MrNaishadh
@MrNaishadh 3 жыл бұрын
this is good..!!
Can you add or subtract two pointers?
9:49
CodeVault
Рет қаралды 7 М.
When to free memory in C
13:45
CodeVault
Рет қаралды 10 М.
УЛИЧНЫЕ МУЗЫКАНТЫ В СОЧИ 🤘🏻
0:33
РОК ЗАВОД
Рет қаралды 7 МЛН
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН
How to measure memory usage inside my program? (getrusage)
13:08
Jacob Sorber
Рет қаралды 31 М.
How to print in binary
18:35
CodeVault
Рет қаралды 17 М.
understanding ft_printf
11:23
nikito
Рет қаралды 16 М.
you will never ask about pointers again after watching this video
8:03
How Memory Usage Slows Down Your Programs
9:17
Jacob Sorber
Рет қаралды 19 М.
How to properly deal with dynamically allocated memory
13:44
CodeVault
Рет қаралды 9 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 102 М.
Cursed C++ Casts
17:41
Logan Smith
Рет қаралды 79 М.
Essentials: Pointer Power! - Computerphile
20:00
Computerphile
Рет қаралды 467 М.
Arrays as function parameters in C
13:28
CodeVault
Рет қаралды 12 М.