What is difference between uninitialized pointer and null pointer?

Answer:
An uninitialized pointer is a pointer which points unknown memory location while null pointer is pointer which points a null value or base address of segment. 

For example:
int *p;   //Uninitialized pointer
int *q= (int *)0;  //Null pointer
#include<stdio.h>
int *r=NULL;   //Null pointer
What will be output of following c program?

#include<string.h>
#include<stdio.h>
void main(){
    char *p;  //Uninitialized pointer
    char *q=NULL;   //Null pointer;
    strcpy(p,"cquestionbank");
    strcpy(q,"cquestionbank");
    clrscr();
    printf("%s  %s",p,q);
    getch();
}

Output: cquestionbank  (null)

No comments: