C language |
Null Pointer:
The simple meaning of null pointer is, the pointer which is pointing to null value i.e we can say pointer which is pointing to nothing. Null pointer identically points to the base address of memory segment.
Examples of NULL pointer:
1. int *ptr=(char *)0;
2. float *ptr=(float *)0;
3. char *ptr=(char *)0;
4. double *ptr=(double *)0;
5. char *ptr=’\0’;
6. int *ptr=NULL;We cannot copy any thing in the NULL pointer.
Example:
#include <stdio.h>
#include <string.h>
int main(){
int main(){
char *ptr=NULL;
strcpy(ptr,"newtechshow.blogspot.com");
strcpy(ptr,"newtechshow.blogspot.com");
printf("%s",ptrr);
return 0;
return 0;
}
This program will give output : null (or segment fault).
Application
This program will give output : null (or segment fault).
Application
- At the end of the linked list, last node's pointer is always null. so that the linked list terminates there otherwise it goes to infinite if last pointer points to garbage values.