Return a value
Make a function hand back a number. An easy embedded C problem (First steps in C), run and graded in the browser.
easy · First steps in C · functions · return
A function is a named piece of code that produces a result. The word before its name says what kind of result: int means a whole number.
Make answer return the number 42.
Starter code
int answer(void) {
// Replace the 0 with the value this function should hand back.
return 0;
}Example tests
Returns 42
printf("%d\n", answer());Expected output:
42Learn it first
- Microcontrollers and your first program · What a microcontroller is, how code gets onto it, and the parts of a C program.
More First steps in C problems
- Add two numbers · Use the inputs a function receives.
- Fix a compiler error · Read an error message and repair the code.
- Minutes to seconds · Convert a duration with one multiplication.
- Area of a rectangle · Combine two parameters into one result.
- Print a line · Send text to the output with printf.
- Print a number · Put a value into printed text with a placeholder.