Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

What is difference between uninitialized pointer and null pointer in C

2 Answers

0 votes
Uninitialized pointer points to unknown memory location, and null pointer points to null value


answered May 6, 2017 by avibootz
0 votes
#include <stdio.h> 

// Uninitialized pointer points to unknown memory location, and null pointer points to null value

int main(int argc, char **argv) 
{ 
    int *p; // Uninitialized pointer
    int *np = NULL; // Null pointer
        
    printf("%d\n", (int)sizeof(p));     
    printf("%d\n", (int)sizeof(np)); 
    
    printf("%p\n", p); // warning: 'p' is used uninitialized in this function 
    printf("%p\n", np);
    
    // Error program crushed:
    //*p = 100;
    //*np = 33;
    //printf("%d\n", *p); 
    //printf("%d\n", *np);
        
    return(0);
}

 
 
/*
 
run:
 
8
8
0000000000000000
0000000000000000
 
*/

 



answered May 6, 2017 by avibootz

Related questions

5 answers 312 views
1 answer 86 views
2 answers 154 views
154 views asked May 5, 2017 by avibootz
1 answer 87 views
1 answer 95 views
1 answer 108 views
...