char *

A C string is just a bunch of characters right next to each other in memory. The string ends when the character 0x00 is encountered.

Figure 39.1  The word “Love” as a C string

The word “Love” as a C string

Functions that take C strings expect the address of the string’s first character. strlen(), for example, will count the number of characters in a string. Try building a string and using strlen() to count the letters:

#​i​n​c​l​u​d​e​ ​<​s​t​d​i​o​.​h​>​ ​ ​/​/​ ​F​o​r​ ​p​r​i​n​t​f​
#​i​n​c​l​u​d​e​ ​<​s​t​d​l​i​b​.​h​>​ ​/​/​ ​F​o​r​ ​m​a​l​l​o​c​/​f​r​e​e​
#​i​n​c​l​u​d​e​ ​<​s​t​r​i​n​g​.​h​>​ ​/​/​ ​F​o​r​ ​s​t​r​l​e​n​ i​n​t​ ​m​a​i​n​ ​(​i​n​t​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.