snipplets.dev/code/Arduino/variables_sizes.ino

74 lines
1.8 KiB
Arduino
Raw Normal View History

/**
* Скетч, который выводит в Serial размер типов переменных в байтах
*/
2023-09-03 11:41:30 +03:00
void setup() {
Serial.begin(9600);
size_t size_variable;
int example_int;
unsigned int example_uint;
signed int example_sint;
unsigned long example_ulint;
float example_float;
double example_double;
char example_char;
char * example_string;
2023-09-19 02:28:04 +03:00
bool example_bool;
2023-09-03 11:41:30 +03:00
size_variable = sizeof(example_int);
Serial.print("int bytes size: " );
Serial.println(size_variable);
size_variable = sizeof(example_uint);
Serial.print("unsigned int bytes size: " );
Serial.println(size_variable);
size_variable = sizeof(example_sint);
Serial.print("signed int bytes size: " );
Serial.println(size_variable);
size_variable = sizeof(example_ulint);
Serial.print("unsigned long bytes size: " );
Serial.println(size_variable);
size_variable = sizeof(example_float);
Serial.print("float bytes size: " );
Serial.println(size_variable);
size_variable = sizeof(example_double);
Serial.print("double bytes size: " );
Serial.println(size_variable);
size_variable = sizeof(example_char);
Serial.print("char bytes size: " );
Serial.println(size_variable);
size_variable = sizeof(example_string);
Serial.print("char * bytes size: " );
Serial.println(size_variable);
2023-09-19 02:28:04 +03:00
size_variable = sizeof(example_bool);
Serial.print("bool bytes size: " );
Serial.println(size_variable);
2023-09-03 11:41:30 +03:00
}
void loop() {
//
}
2023-09-19 01:22:13 +03:00
/**
* Arduino Nano
*
* int bytes size: 2
* unsigned int bytes size: 2
* signed int bytes size: 2
* unsigned long bytes size: 4
* float bytes size: 4
* double bytes size: 4
* char bytes size: 1
* char * bytes size: 2
2023-09-19 02:28:04 +03:00
* bool bytes size: 1
2023-09-19 01:22:13 +03:00
*/