# Difference between #define and const in Arduino

ArduinoHardwareSoftware & Coding

#### Arduino Long Distance Communication

14 Lectures 1 hours

#### Arduino Wireless Power Transmission

13 Lectures 50 mins

#### Arduino Car Parking Assistant

9 Lectures 42 mins

If you've done sufficient Arduino programming, you'd have seen that there are two ways of defining constants.

### #define

One way is to use #define, like

#define const_name 3

### const

The other way is to use the const keyword, like

const int var_name = 3;


### Difference between #define and const

#define is like a placeholder. The Arduino compiler replaces all mentions of this constant with its value at the compile time. This means that the values defined using #define don't take up any program space.

Variables defined using const, on the other hand, are just normal variables, whose values can't be changed. They take up program memory space, and have a type (which is advantageous in many situations).

In general, it is preferred to use const over #define, for defining constants.

Updated on 24-Jul-2021 14:34:44