Return Function in C

Level 392 keystrokes

Defines a function that returns the square of an integer.

C code

// Takes an int and returns an int
1int square(int n) {
// Send n squared back to the caller
2 return n * n;
3}
4
// The returned value 49 is stored in result
5int result = square(7);
// Print Square: 49
6printf("Square: %d\n", result);

Output

Square: 49
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.

  • ;× 3
  • (× 3
  • )× 3
  • "× 2
  • ,× 1
  • :× 1
  • {× 1
  • }× 1
  • *× 1
  • \× 1

More C examples at level 3

← C typing practice