Sign in to follow this  

Quick question

Recommended Posts

foo in itself is just fine, as the storage duration of string literals is for the lifetime of the program.

The use of foo in main however, is not fine. It tries to assign a pointer-to-const-char to a pointer-to-char, which is not legal. The other way around would be fine, assigning from pointer-to-char to pointer-to-const-char.

You may be confused by the legacy rules that you may assign a string literal to a pointer-to-char assuming you do not attempt to modify the contents of the literal, due to APIs from the days where there were no const.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this