Like Tree3Likes
  • 3 Post By Click_here

Does static initialization of pointer make it null pointer

This is a discussion on Does static initialization of pointer make it null pointer within the C Programming forums, part of the General Programming Boards category; Does the following code make p as a null pointer static int *p; since Code: printf("%u",p); outputs as 0 though ...

  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,344
    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, 08:08 PM
  2. Struct pointer initialization
    By pe4enka in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2010, 04:16 AM
  3. Pointer Initialization Within A Struct
    By SMurf in forum C Programming
    Replies: 15
    Last Post: 02-09-2009, 10:27 AM
  4. initialization of double pointer with new
    By GaPe in forum C++ Programming
    Replies: 8
    Last Post: 01-19-2005, 10:09 AM
  5. Replies: 2
    Last Post: 10-12-2002, 07:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21