Null termination of C string -


is right null terminating c string automatically added compiler in general?

so in following example:

char * str = "0124"; printf("%x", str[str[3] - str[2] + str[4]]); 

the output 32?

thanks.

yes, compiler add null terminator. there 5 bytes of memory allocated str off stack.

by looks of it, string literal, (str[3] - str[2] + str[4]) evaluates (52 - 50 + 0), acessing str[2], print 0x32 in hex.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -