Sizeof - Fundamental Data Type

Hi everyone, I'm trying to figure out what fundamental data type sizes are e.g.:

std::cout << "int:\t\t" << sizeof(int) << " bytes\n";

Is there some way of finding out the size of an int that an Arduino uses?

Couldn't find a more appropriate section so putting it in general. To mods: if you know a better place, please move.

Surely the obvious way would be to use the sizeof() macro


(Bizarrely, it's an operator, not a macro)

Well at least I didn't call it a function

Thanks guys, great info!

Considering that you posted

std::cout << "int:\t\t" << sizeof(int) << " bytes\n";

I am surprised that you did not try sizeof() in the first place. After all, the Arduino is programmed in C++

Well I'm still learning C++ but with C++ you have an OS with an operating system which has a terminal. Arduino doesn't have a terminal, so I was out of ideas about how to talk to it. I still don't know what your Serial.println(sizeof(double)); will do, but coupled with the link to the documentation I should be able to eventually figure this out. At least I now know that there is some kind of communication happening between the Arduino and the computer through the serial port and I would imagine there is something that will appear in the Tools->Serial Monitor window. I guess that's Arduino's terminal. Reading the documentation now.


You were almost calling it (sizeof(int)) a function because of having a pair of parentheses accepting its argument?

byte y = sizeof(int);
size_t serialSize = sizeof Serial;

What parentheses? :wink:

1. In Arduino UNO where we have 8-bit MCU, the size of int data type is 2-byte:

byte n = sizeof(int);   // n = 2 bytes = 16-bit
Serial.println(n, DEC);    //shows: 2 ==> 2 bytes = 16-bit

2. In Arduino DUE where we have 32-bit MCU, the size of int data type is 4-byte.

byte n = sizeof(int);   // n = 4 bytes = 32-bit
Serial.println(n, DEC);    //shows: 4 ==> 4 bytes = 32-bit

Exactly! The Serial Monitor is the Arduino's Terminal(Fig-1, Fig-2)



'(' is called "Opening Parenthesis" and ')' is called "Closing Parenthesis". "( )" is called "Pair of Parentheses". I am a non-native and that's all I know.

Sorry, I of course just meant OS with a terminal. Typed OS twice.

I was simply pointing-out the absence of any parentheses in the (correct) example I gave; nothing to do with spelling.

Still nope

This is the style (sizeof int) I prefer to use; because, sizeof (being a keyword) is not a function name - it is an operator which you have also mentioned.


size_t sizeInt = sizeof int;

doesn't compile, so why would you prefer that?

Just now discovered that for the sizeof operator to work on a keyword like int, the argument should be within ( ). For example:

byte n = sizeof(int);

For arguments other than keyword, sizeof works on both styles -- with and without ( ).