Strings in C



char c[] = "c string";

can declare. eg

char s[6];
s = "hello";

Can over declare, givng spare space.

char c[50] = "hello";

Null character

Compiler adds null character automatically.
0 is null character.

char c[] = {"h", "e", "l", "l", "o", "\0"};

Strings and pointers

Strings are arrays of characters, and so we can use pointers to access.

\(c\) returns \("h"\). \((c+1)\) returns \("e"\).



Can represent same information in multiple ways?

American Standard Code for Information Interchange (ASCII)

UTF (Unicode)


strings as data type. similar to array? but diff functions. eg find "cat" in "concatenate"

can subinstr. upper. lower. proper. strpos

can regex. section on regex in data types?

character: number maps to character

string literals

array of chars

buffer overflows on strings (already discussed them in the context of arrays)

can use sizeof. size determined at compile time

null terminated string

string literals: escaping characters