Thread: Does static initialization of pointer make it null pointer

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    50

    Does static initialization of pointer make it null pointer

    Does the following code make p as a null pointer
    static int *p;


    since
    Code:
    printf("%u",p);
    outputs as 0


    though the syntax is

    Code:
    int *p=NULL or int *p=0

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    This is from the C11 Standard

    10 If an object that has automatic storage duration is not initialized explicitly, its value is
    indeterminate. If an object that has static or thread storage duration is not initialized
    explicitly, then:
    — if it has pointer type, it is initialized to a null pointer;
    — if it has arithmetic type, it is initialized to (positive or unsigned) zero;
    — if it is an aggregate, every member is initialized (recursively) according to these rules,
    and any padding is initialized to zero bits;
    — if it is a union, the first named member is initialized (recursively) according to these
    rules, and any padding is initialized to zero bits;
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer Initialization
    By johan.g1 in forum C Programming
    Replies: 6
    Last Post: 11-14-2012, 09:08 PM
  2. Struct pointer initialization
    By pe4enka in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2010, 05:16 AM
  3. Pointer Initialization Within A Struct
    By SMurf in forum C Programming
    Replies: 15
    Last Post: 02-09-2009, 11:27 AM
  4. initialization of double pointer with new
    By GaPe in forum C++ Programming
    Replies: 8
    Last Post: 01-19-2005, 11:09 AM
  5. Replies: 2
    Last Post: 10-12-2002, 07:44 PM