top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference between uninitialized pointer and null pointer?

0 votes
472 views
What is difference between uninitialized pointer and null pointer?
posted Mar 17, 2016 by Mohammed Hussain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Uninitialized pointer may contain garbage value and accessing an invalid address may cause segmentation fault.
Programmers always guard invalid access of pointer by putting cross check against the NULLP. As per good programming practices always assign NULLP to a pointer which does not hold a valid address.
Example:
int *p ; // uninitialized pointer
int *p = NULL; // initialized with NULL.

answer Mar 17, 2016 by Vimal Kumar Mishra
0 votes

int* ptr = NULL; //Is this going to avoid the problem
This will cause ptr to point to NULL which you can explicitly check for as a default/uninitialized value. It prevents the problem, but a careless programmer can still accidentally dereference a null pointer without checking, causing undefined behaviour.

answer Mar 20, 2016 by Rajan Paswan
Similar Questions
0 votes

What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

+1 vote

int arr[ ] = { 1, 2 };
p = arr; /* p is pointing to arr */

How pointer p will behave ?

...