0 day streak
c / beginner
Snippet

Initializing Strings

In C, strings are simply arrays of characters. You use double quotes for strings and single quotes for individual characters.

snippet.c
c
1
2
char greeting[] = "Hello";
char singleLetter = 'A';
Breakdown
1
char greeting[] = "Hello";
Creates a character array that holds the string 'Hello' plus a hidden null terminator.
2
char singleLetter = 'A';
Stores exactly one character in a char variable using single quotes.