I'm trying to understand how passing pointers to functions work, but I don't understand the following situation : Why this code work
void setVar(uint32_t* var) {
*var = 10;
}
int main() {
uint32_t myVar = 0;
setVar(&myVar);
return 0;
}
and this one lead to a runtime error ? :
void setVar(uint32_t* var) {
*var = 10;
}
int main() {
uint32_t* myVar = 0;
setVar(myVar);
return 0;
}
I'd appreciate your answers.