Pointers - scope and lifetime

  Рет қаралды 1,615

Siemens Embedded

Siemens Embedded

Күн бұрын

Пікірлер: 11
@mironovtt
@mironovtt 4 жыл бұрын
You are doing great job! Keep it up, sir! 👍👍👍
@kolhatkarchinmay
@kolhatkarchinmay 4 жыл бұрын
Good Example of Dangling pointer. Collin please upload similar concept video for malloc, calloc and free functions.
@AtAGlimpse_UB
@AtAGlimpse_UB 3 жыл бұрын
I just want to say one thing. Whenever your Microcontroller gets into the infinite loop when you step up your code, that might be due to the pointer pointing to a address which is not existing.
@asafcohen3562
@asafcohen3562 4 жыл бұрын
This is great
@1willFALL
@1willFALL 4 жыл бұрын
Could you do a video on function pointers and maybe also on FILE I/O?
@rafalzasada8826
@rafalzasada8826 4 жыл бұрын
If malloc() returns just a pointer how program know what amount of memory is allocated and can't be used for anything else? The same goes for free() function - if we pass just a pointer to it how program knows what amount of memory became available ? Pointer is just a pointer, sizeof(*p) does not work so where is that information stored about a size?
@leviengel
@leviengel 6 ай бұрын
When using malloc. you basically request the amount of memory you need, the OS, look for that amount of memory in the HEAP region of RAM and if found the amount of memory requested, returns a pointer to the start of that chunk of memory. It is the responsability of the programer to manage and keep track of that memory. That's why when using malloc you have to cast that pointer to the size of datatype you will be using. If malloc does not find the amount of memory you require, it will return a NULL pointer. A pointer has metadata containing information of the size of memory it points to, that's how the OS knows how much memory free.
@muhammadinamulhaq3622
@muhammadinamulhaq3622 4 жыл бұрын
I've a question. If I return the address of array from a function, and use this code x = *(p+3); will it return the right element at that location? or system might use that memory to change the contnts and I might get a wrong value stored in that memory?
@kolhatkarchinmay
@kolhatkarchinmay 4 жыл бұрын
No it will cause segmentation falut. As memory location assigned to arr[ ] is already removed out of stack. So p already containing invalid location. So doing any operation with p is invalid.
@muhammadinamulhaq3622
@muhammadinamulhaq3622 4 жыл бұрын
@@kolhatkarchinmay but p has a memory address and I'm pointing to some value at address *(p+3) so it should be valid. Question is if the data Will be same or as the arr is not there anymore and we've not used malloc so the system might usw the memory and put some other data.
@joaquinortiz279
@joaquinortiz279 4 жыл бұрын
@@muhammadinamulhaq3622 as before mentioned, it will cause a segmentation fault. Don't worry about the data value when you are pointing to undefined memory addresses
C++ exception handling
5:35
Siemens Embedded
Рет қаралды 3,8 М.
Dynamic memory in real time systems - a solution?
6:30
Siemens Embedded
Рет қаралды 3,1 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
RISC-V - the latest embedded fashion
5:46
Siemens Embedded
Рет қаралды 1,7 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
Structures and classes in C++
6:01
Siemens Embedded
Рет қаралды 957
Multicore - technology and terminology
5:41
Siemens Embedded
Рет қаралды 1,6 М.
What are double pointers in C?
14:43
CodeVault
Рет қаралды 46 М.
Object Lifetime in C++ (Stack/Scope Lifetimes)
11:00
The Cherno
Рет қаралды 165 М.
How one thread listens to many sockets with select in C.
12:01
Jacob Sorber
Рет қаралды 103 М.
Some C++ questions
5:40
Siemens Embedded
Рет қаралды 799
Pointers and arrays
8:43
mycodeschool
Рет қаралды 654 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН