9t8
9t8

Reputation: 9

Is the address of a string literal guaranteed not to be null?

Is it guaranteed that "stuff" != nullptr and "" != nullptr?

An online search did not give useful results.

Edit: I am asking if it is guaranteed that the address of any string literal is not null, which neither of the duplicate questions explicitly answers.

Upvotes: 0

Views: 77

Answers (1)

KamilCuk
KamilCuk

Reputation: 141493

Is the address of a string literal guaranteed not to be null?

Yes.

A null pointer cannot be derefernced. A string literal can be converted to a pointer, which can be dereferenced to get the first character of the string. Ergo, a string literal can't be a null pointer. Q.E.

Upvotes: 1

Related Questions