String Variable in C

Level 244 keystrokes

Stores the string "Alice" in a char array, which is how C represents strings, and prints it with %s.

C code

// C has no string type: a string is a char array ending in '\0'
// The size is taken from the initializer: 5 letters + '\0' = 6
1char name[] = "Alice";
// %s prints the characters up to '\0', so this prints "Alice"
2printf("%s\n", name);

Output

Alice
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C code and how often they appear.

  • "× 4
  • ;× 2
  • ,× 1
  • (× 1
  • )× 1
  • [× 1
  • ]× 1
  • \× 1
  • %× 1
  • =× 1

More C examples at level 2

← C typing practice