Character Array in C

Level 385 keystrokes

Iterates through a character array until the null terminator is reached.

C code

// The compiler adds '\0' after the last letter
1char str[] = "Hello";
// The condition tests the character, so no length is needed
2for (int i = 0; str[i] != '\0'; i++) {
// %c prints one character; the output is H e l l o
3 printf("%c ", str[i]);
4}

Output

H e l l o
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
  • "× 4
  • [× 3
  • ]× 3
  • =× 3
  • '× 2
  • (× 2
  • )× 2
  • +× 2
  • ,× 1

More C examples at level 3

← C typing practice