pointer-type initialization

From cppreference.com
< c‎ | language

Template:c/language/initialization/navbar

This is the initialization performed when a pointer is constructed.

[edit] Explanation

If an object has pointer type and has automatic storage duration and is not initialized explicitly, its initial value is indeterminate.

If an object has pointer type and has static storage duration and is not initialized explicitly, its initial value is NULL.

The initializer for a pointer shall be a single expression, optionally enclosed in braces. The initial value of the object is that of the expression (after conversion); the same type constraints and conversions as for simple assignment apply, taking the type of the pointer to be the unqualified version of its declared type.

[edit] Example

#include <stdio.h>
 
int main(void)
{
    int a = 1;
 
    int *p1;             /* initial value is indeterminate            */
    static int *p2;      /* initial value is NULL                     */
    int *p3 = &a;        /* initial value is the address of an object */
    int *p4 = {&a};      /* optional braces                           */
 
    printf("%p\n", (void*)p1);
    if (p2==NULL) printf("null pointer\n");
    printf("%d\n", *p3);
    printf("%d\n", *p4);
 
    return 0;
}

Possible output:

(nil)
null pointer
1
1