Is the global pointer initialized to zero?

I was wondering what the cpp standard says about global initialization. I found this answer useful, but there was no indication of the type of pointer.

Is there a guarantee that this will work?

char* myptr
int main()
{
    if (myptr == NULL)
    {
        std::cout << "All good!" << std::endl;
    }
}
+4
source share
2 answers

Yes, a pointer defined in the namespace area (the global namespace in your case) is guaranteed to be initialized to the null value of the null type pointer.

For standard links

3.6.2[basic.start.init]/2 "Variables with static storage duration ... must be initialized to zeros (8.5)"

8.5[dcl.init]/6 "To zero-initialize... : T (3.9), , 0 () T; [106]"

106). 4.10, , 0 , null .

( )

+8

@Cubbi,

(3.9.1), , , (3.9.2), std:: nullptr_- t cv- (3.9.3)

.

(3.7.1) (3.7.2) (8.5) .

+4

All Articles