Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Uninitialized pointers in C
#1
Using pointers without initializing them or dereferencing NULL pointers can lead to crashes.

// Incorrect
int *ptr; // Uninitialized pointer
*ptr = 10; // Dereferencing NULL pointer

// Correct
int *ptr = NULL;
ptr = (int *)malloc(sizeof(int));
*ptr = 10;
free(ptr);
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File pointers and streams in C Qomplainerz 0 223 07-25-2023, 01:24 PM
Last Post: Qomplainerz
  Passing pointers to functions in C Qomplainerz 0 276 07-25-2023, 11:42 AM
Last Post: Qomplainerz
  Understanding pointers and memory addresses in C Qomplainerz 0 242 07-25-2023, 11:41 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 6 Guest(s)