Pointers - scope and lifetime

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

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 3 ай бұрын
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
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 329 М.
RISC-V - the latest embedded fashion
5:46
Siemens Embedded
Рет қаралды 1,7 М.
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 19 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 16 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 78 МЛН
you will never ask about pointers again after watching this video
8:03
Dynamic memory in real time systems - a solution?
6:30
Siemens Embedded
Рет қаралды 3,1 М.
C++ exception handling
5:35
Siemens Embedded
Рет қаралды 3,7 М.
Object Lifetime in C++ (Stack/Scope Lifetimes)
11:00
The Cherno
Рет қаралды 162 М.
Selecting an embedded CPU
4:58
Siemens Embedded
Рет қаралды 1,4 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
TCP/IP for Programmers
3:03:31
Eli the Computer Guy
Рет қаралды 231 М.
Multicore - technology and terminology
5:41
Siemens Embedded
Рет қаралды 1,5 М.
Exception Handling In C++ Introduction
10:27
CppNuts
Рет қаралды 4,5 М.