Build Your Own AI Assistant Part 1 - Creating the Assistant
116820 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
114678 Views
Control Arduino with Python using Firmata / PyFirmata
87081 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
57314 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
53588 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
52067 Views
LEGO Gets Lights & Sound with Tiny FX
Thinkman
Podman vs Docker
MicroPython Robotics
Bottango and Isaaca
LidarBot
Getting Started with C on the Raspberry Pi Pico
0h 20m
Running K3s on Raspberry Pi
0h 36m
From Docker to Podman
0h 28m
MicroPython Robotics Projects with the Raspberry Pi Pico
0h 24m
Bottango Basics
0h 22m
Mini-Rack 3D Design Tutorial
Learn how to Program in Python, C, Rust, and more.
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
50% Percent Complete
By Kevin McAleer, 3 Minutes
Page last updated June 15, 2025
As your programs grow, it becomes helpful to organize your code into functions. Functions let you name a block of code and call it whenever you need it — this keeps your code clean, reusable, and easier to understand.
A function is like a mini-program you can define and reuse. Every C program starts with a special function called main() — that’s where the program begins.
main()
Here’s a simple function:
void greet() { printf("Hello from a function!\n"); }
This function uses the printf() function to print a message. Functions can contain other functions, variables, and logic just like the main program.
printf()
The \n at the end of the string is a newline character, which moves the cursor to the next line after printing.
\n
To run the function, just call it by name:
int main() { greet(); // this runs the greet() function return 0; }
Syntax means the rules for how to write code correctly.
Syntax
Here’s the basic structure of a function in C:
return_type function_name(parameter_list) { // code to execute }
The parts are:
int
void
greet
int a, int b
void say_hello(char name[]) { printf("Hello, %s!\n", name); }
the char name[] part is a parameter that lets you pass in a name when you call the function. The square brackets [] indicate that name is an list of characters (a string).
char name[]
[]
name
Call it like this:
say_hello("Kevin");
int add(int a, int b) { return a + b; } int main() { int result = add(2, 3); printf("Result: %d\n", result); return 0; }
Quick Tips Declare functions before calling them (or use a function prototype) Always match the number and type of arguments void means “no return value”
You now know how to:
Next up: Setting Up the Toolchain, where we’ll install the software you need to compile and upload C programs to the Raspberry Pi Pico.
< Previous Next >
You can use the arrows ← → on your keyboard to navigate between lessons.
← →