Arduino programming primarily uses C++.
While Arduino sketches are often written using a simplified structure that resembles C, the underlying language and the core Arduino libraries are written in C++. The Arduino Integrated Development Environment (IDE) compiles your code using a C++ compiler.
Understanding Arduino's Language
Here's why Arduino is considered C++:
- Compiler: The Arduino IDE uses a C++ compiler (like avr-g++ or arm-none-eabi-g++).
- Libraries: The extensive set of built-in and third-party Arduino libraries are predominantly written in C++. This includes essential components for controlling hardware, communication, and more.
- Preprocessing: When you write an Arduino "sketch" in a
.ino
file, the IDE performs some preprocessing (like generating function prototypes) before passing the code to the C++ compiler. - Modern Applications: As highlighted in the reference, for features like connecting to the Arduino Cloud, C++ is the designated language: "The default option for programming your board to connect to the Arduino Cloud is by using the C++ language. The configuration and connection between your board and the Arduino Cloud is supported by the ArduinoIoTCloud library & Arduino_ConnectionHandler libraries."
The C Connection
It's important to note that since C++ is largely a superset of C, you can write valid C code within an Arduino sketch. Many of the fundamental operations and data types come directly from C. However, you gain access to C++ features like:
- Classes and objects (used extensively in libraries)
- Constructors and destructors
- Inheritance
- Polymorphism
- References
- Templates
These C++ features are leveraged heavily in the structure and design of the Arduino framework and its libraries, providing a more modular and powerful way to write code for complex projects.
Key Takeaways
- Arduino sketches are compiled as C++ code.
- The vast majority of Arduino libraries are written in C++.
- You benefit from C++ features and object-oriented programming capabilities.
- While C syntax is valid, the overall environment is C++.
In essence, when you program an Arduino board, you are writing C++ code that is processed and compiled by a C++ toolchain.