Data Types Interview Questions for Embedded C: Standard Types Quiz
16 multiple choice questions, 12 fill-in-the-blank items, a type-identification table, 8 true/false statements, 6 code snippet challenges and 12 detailed interview questions with verified answers.
50
Questions
Beginner → Advanced
Level
Live score
Auto-graded
Live Score Tracker
0 Correct
0 Wrong
0 Attempted
Answer the auto-graded questions (MCQ, fill-in, true/false) to see your score.
Section 1: Multiple Choice Questions — Standard C Data Types
These data types interview questions in multiple-choice form test sizes, signedness and formats. Click your answer; explanations always appear, correct or not.
1. Which statement about sizeof(char) is true?
The standard defines sizeof(char) as exactly 1. All other sizes are measured in units of char.
2. What is sizeof(int) with arm-none-eabi-gcc on the STM32F407?
ARM Cortex-M uses the ILP32 model: int = 4 bytes.
3. On a 64-bit Linux PC (LP64), sizeof(long) is:
LP64 makes long and pointers 64-bit. On 64-bit Windows long stays 4.
4. Which relation is guaranteed by the C standard?
Only the ordering (and minimum ranges) is guaranteed, not the exact sizes.
5. Plain char with GCC for ARM is:
The ARM EABI specifies unsigned char; x86 GCC uses signed. That is why uint8_t is preferred for bytes.
6. Which printf specifier is correct for a size_t (the result of sizeof)?
%zu is the C99 length modifier for size_t.
7. A 12-bit ADC result (0..4095) is best stored in:
1 / 4 is an integer division = 0, then converted to 0.0f.
9. The STM32F407 FPU supports:
The Cortex-M4F has an FPv4-SP unit: single-precision only. double uses a slow software library.
10. What is the range of unsigned short on ARM?
16 bits: 0 to 216 − 1.
11. Which header defines INT_MAX?
<limits.h> holds integer limits; <float.h> the floating-point ones.
12. What is uint8_t x = 255; x++; afterwards?
Unsigned arithmetic wraps modulo 256, so x becomes 0. It is fully defined.
13. What does the type void * represent?
It is a generic pointer: it can hold any object address but must be cast before dereferencing.
14. Which literal is a float rather than a double?
The f suffix makes a float; no suffix means double; L means long double.
15. Which comparison is the correct way to test two floats for near-equality?
Rounding errors make exact comparison unreliable; compare against a small tolerance.
16. A program prints -56 for char c = 200; on a PC but 200 on the STM32F407. The reason is:
Signed char on x86, unsigned char on ARM: the same bits 0xC8, different interpretation.
Section 2: Fill in the Blanks
Fill-in items are common data types interview questions too. Spaces and capitalisation are ignored; you may type the minus sign as -.
1. sizeof(short) on the STM32F407 is bytes
A short is 16 bits.
2. UCHAR_MAX equals
28 − 1.
3. After uint8_t x = 250; x += 10; the value of x is
260 mod 256 = 4.
4. The header that defines INT_MAX is
<limits.h>.
5. The printf specifier that prints hexadecimal with capital letters is
%X (capital), %x (lower case).
6. sizeof(double) on ARM Cortex-M4 is bytes
64-bit IEEE-754.
7. The maximum of unsigned short (decimal) is
216 − 1.
8. The minimum of a signed 16-bit integer is
−215.
9. The suffix letter that makes 2.5 a float literal is
2.5f.
10. sizeof(long long) is bytes on every common platform
long long is at least 64 bits.
11. The specifier that prints a single character is
%c.
12. A 12-bit ADC can produce different values
212 = 4096 (0..4095).
Section 3: Identify the Data Type
A classic of data types interview questions: choose the most suitable type for each use case on the STM32F407.
Use case
Your answer
Result
Value of a UART received byte (0..255)
uint8_tchar []int16_tuint32_tuint64_tfloatvoid
Name of a person (text)
uint8_tchar []int16_tuint32_tuint64_tfloatvoid
Room temperature in °C with sign, to 0.1 °
uint8_tchar []int16_tuint32_tuint64_tfloatvoid
A 32-bit peripheral register
uint8_tchar []int16_tuint32_tuint64_tfloatvoid
Milliseconds since boot (wraps after 49 days is acceptable)
uint8_tchar []int16_tuint32_tuint64_tfloatvoid
Microseconds since boot for a device running for years
uint8_tchar []int16_tuint32_tuint64_tfloatvoid
PID controller gain 0.75
uint8_tchar []int16_tuint32_tuint64_tfloatvoid
Callback that returns no value
uint8_tchar []int16_tuint32_tuint64_tfloatvoid
Section 4: True or False
Short true/false statements are a favourite opener in data types interview questions.
1. sizeof(int) is 4 on every platform.
It is 2 on AVR and MSP430 and 4 on ARM and most PCs.
2. sizeof(char) is always 1.
By definition of the C standard.
3. Plain char has the same signedness on all compilers.
It is implementation-defined: unsigned on ARM, signed on x86.
4. Unsigned integer overflow wraps around and is well defined.
Arithmetic is modulo 2N.
5. You can declare a local variable of type void.
void has no values; only void * variables are allowed.
6. The STM32F407 has hardware support for double.
Its FPU is single-precision only.
7. float f = 0.1; stores exactly 0.1.
0.1 has no exact binary representation; the stored value is about 0.100000001490116.
8. printf("%d", some_long_long) is safe on a 32-bit platform.
The argument is 8 bytes but %d reads 4: undefined behaviour. Use %lld.
Section 5: Code Snippet Challenges
These code snippets are the practical side of data types interview questions. Predict, repair or complete each program. Every answer shown was produced by compiling and running the code.
Challenge 1 — Output?: sizeof of arrays and promoted expressions
#include <stdio.h>int main(void)
{
int a[5];
short s = 1;
printf(“%zu %zu %zu\n”, sizeof(a), sizeof a / sizeof a[0], sizeof(s + s));
return0;
}
What does this print on a platform with 4-byte int and 2-byte short?
Output:20 5 4 sizeof(a) = 5 × 4 = 20; dividing by the element size yields the element count 5; and s + s is promoted to int before the addition, so its size is 4, not 2.
Challenge 2 — Find the bug: The wrong average
#include <stdio.h>int main(void)
{
int a = 7, b = 2;
float avg = (a + b) / 2;
printf(“average = %.2f\n”, avg);
return0;
}
Expected 4.50. What is printed and what is the fix?
Output:average = 4.00 (a + b) / 2 is integer division (9 / 2 = 4) before the conversion to float. Fix: (a + b) / 2.0f or (float)(a + b) / 2.
Challenge 3 — Output?: Promotion hides the wrap
#include <stdio.h>#include <stdint.h>int main(void)
{
uint8_t a = 200, b = 100;
printf(“%d %d\n”, a + b, (uint8_t)(a + b));
return0;
}
What are the two numbers printed?
Output:300 44 a + b is computed as int (both operands are promoted), giving 300. Only after the cast to uint8_t does it wrap: 300 mod 256 = 44.
Challenge 4 — Complete: The 64-bit format specifier
#include <stdio.h>int main(void)
{
unsignedlonglong big = 1ULL << 40;
printf(“???\n”, big); /* choose the right specifier */return0;
}
Replace ??? so the program prints 1099511627776.
Answer:%llu (unsigned long long).
1099511627776
With %u or %lu on a 32-bit target, the wrong number of bytes is read and the output is garbage.
Challenge 5 — Find the bug: Millisecond timer too narrow
What is printed for 70000 ms, and why is this a problem for a timeout?
Output:4464 70000 mod 65536 = 4464: a 16-bit millisecond counter wraps every 65.5 s, so a 70-second timeout would fire after 4.4 s. Use uint32_t (wraps after 49.7 days).
#include <stdio.h>#include <math.h>int main(void)
{
float a = 0.1f + 0.1f + 0.1f;
printf(“%d %d\n”, a == 0.3f, fabsf(a – 0.3f) < 1e-6f);
double x = 0.1 + 0.2;
printf(“%d %.17f\n”, x == 0.3, x);
return0;
}
What are the two lines of output? (First line is float, second is double.)
Output:
1 1
0 0.30000000000000004
The float line prints 1 1 here only because three roundings happen to land on the same float; the double line prints 0 because 0.1 + 0.2 is 0.30000000000000004, not 0.3. Whether an exact == succeeds depends on precision and rounding, so it is unreliable. A tolerance test (fabsf(a - b) < eps) is the safe choice.
Section 6: Data Types Interview Questions for Embedded C (with Detailed Answers)
These data types interview questions come up constantly in embedded C interviews. Click a question to see a model answer, then try to explain it aloud in your own words.
Q1. Why can’t I assume that int is 32 bits in embedded C?Basic+
The standard only guarantees that int holds at least −32,767 to +32,767 (16 bits). On 8-bit AVR and 16-bit MSP430 it is 2 bytes, on ARM Cortex-M and most PCs 4 bytes. Code that stores 100,000 in an int works on the STM32F407 and silently breaks on an AVR.
Use fixed-width types (int32_t, uint16_t) from <stdint.h> whenever the exact size matters.
Q2. What is the size of char and is it signed or unsigned?Basic+
sizeof(char) is always 1 by definition (and 8 bits on all mainstream platforms). Its signedness is implementation-defined: unsigned on ARM (EABI), signed on x86 GCC. Use signed char, unsigned char, int8_t or uint8_t when it matters.
Q3. Explain the difference between float and double. Which should you use on the STM32F407?Basic+
float
double
Bits
32
64
Precision
~7 digits
~15 digits
STM32F407
Hardware FPU (1 cycle for add/mul)
Software library, tens of times slower
Use float and the f suffix on literals. Compile with -mfpu=fpv4-sp-d16 -mfloat-abi=hard so the FPU is used.
Q4. What does void mean, and what is void *?Basic+
void means “no value”: no return value, no parameters. You cannot define a void variable. void * is a generic pointer that can hold the address of any object; it must be cast to a concrete pointer type before being dereferenced, and arithmetic on it is not portable. malloc, memcpy and callback “user data” parameters use it.
Q5. What is the portability problem with standard C types, and how do you solve it?Intermediate+
Sizes of int, long and pointers vary between architectures (ILP32, LP64, LLP64, 16-bit). Structure layouts, register overlays, protocol parsers and overflow behaviour then change silently when the code is rebuilt for another target. The solution is: fixed-width types from <stdint.h>, explicit signedness, _Static_assert checks for assumptions, and <inttypes.h> macros for printing.
static_assert.c — catch wrong assumptions at compile time and see layout effects
#include <stdio.h>#include <stdint.h>
_Static_assert(sizeof(uint32_t) == 4, “uint32_t must be 4 bytes”);
_Static_assert(sizeof(int) >= 2, “int too small”);
_Static_assert(sizeof(char) == 1, “never fails”);
struct Mixed { char a; int b; char c; };
struct Packed { int b; char a; char c; };
int main(void)
{
printf(“Mixed = %zu bytes\n”, sizeof(struct Mixed));
printf(“Packed = %zu bytes\n”, sizeof(struct Packed));
return0;
}
Output (verified)
Mixed = 12 bytes
Packed = 8 bytes
The two structures contain the same members, yet their sizes differ because of alignment padding (Module 15).
Q6. What happens if the printf format specifier does not match the argument type?Intermediate+
The behaviour is undefined. Typical results: garbage output (%d given a double), a crash (%s given an integer), or corrupted later arguments (%d given a 64-bit value shifts the argument list on some ABIs). Compile with -Wformat (part of -Wall) to catch it, and use %zu, %lld or PRIu32 for the right widths.
Q7. Why is 0.1 + 0.2 == 0.3 false in C, and how should you compare floats?Intermediate+
0.1, 0.2 and 0.3 cannot be represented exactly in binary floating point; each is rounded. The sum 0.1 + 0.2 is 0.30000000000000004 in double, which differs from the rounded 0.3 by one unit in the last place.
float_compare.c
#include <stdio.h>#include <math.h>int main(void)
{
float a = 0.1f + 0.1f + 0.1f;
printf(“%d %d\n”, a == 0.3f, fabsf(a – 0.3f) < 1e-6f);
double x = 0.1 + 0.2;
printf(“%d %.17f\n”, x == 0.3, x);
return0;
}
Output (verified)
1 1
0 0.30000000000000004
Compare with an absolute or relative tolerance: fabsf(a - b) <= eps * fmaxf(fabsf(a), fabsf(b)).
Q8. A char addition seems to overflow but the sum is correct. Why?Intermediate+
Integer promotion: operands of type char and short are converted to int before arithmetic. The sum is correct as an int and only wraps when you assign it back to a narrow type.
promotion.c
#include <stdio.h>int main(void)
{
char a = 100, b = 100;
int sum = a + b; /* promoted to int: no overflow here */char stored = a + b; /* converted back to char: may be wrong */
printf(“sum = %d, stored = %d\n”, sum, stored);
return0;
}
Output on x86 (signed char). On ARM (unsigned char) stored = 200.
sum = 200, stored = -56
Lesson 3.3 covers promotion and casting in depth.
Q9. How do you print a floating-point temperature on a system where printf does not support %f?Intermediate+
newlib-nano omits float formatting unless you link with -u _printf_float, which costs about 10 KB of flash. The alternative is to split the value into integer parts or to keep the value as a scaled integer from the start:
The + 0.5f rounds to the nearest tenth. Handle negative numbers separately (print the sign first, then work with the absolute value).
Q10. What do ILP32, LP64 and LLP64 mean?Advanced+
Model
int
long
pointer
Platforms
ILP32
32
32
32
ARM Cortex-M, 32-bit x86
LP64
32
64
64
64-bit Linux, macOS, Android
LLP64
32
32
64
64-bit Windows
IP16
16
32
16
AVR, MSP430 (small model)
The letters name the types that are wider than 32 bits. The practical consequence: never assume sizeof(long) == sizeof(void *), and use uintptr_t when you need an integer that can hold a pointer.
Q11. Why is sizeof of a small-type expression sometimes larger than the type?Advanced+
Because of integer promotion the expression s + s (two shorts) has type int, so sizeof(s + s) is 4 while sizeof(s) is 2. sizeof does not evaluate its operand; it uses the operand’s type after promotions and conversions.
sizeof_expr.c
#include <stdio.h>int main(void)
{
short s = 1; char c = 1; float f = 1.0f;
printf(“short:%zu s+s:%zu c+c:%zu f+f:%zu f+1.0:%zu c<1:%zu\n”,
sizeof(s), sizeof(s + s), sizeof(c + c), sizeof(f + f), sizeof(f + 1.0), sizeof(c < 1));
return0;
}
Output (verified)
short:2 s+s:4 c+c:4 f+f:4 f+1.0:8 c<1:4
Note f + 1.0: the literal is a double, so the whole expression becomes double (8 bytes), the performance trap mentioned in the theory.
Q12. How would you choose between int, uint8_t and uint32_t for a loop counter on a Cortex-M4?Advanced+
For a local loop counter, plain int (or unsigned int) is usually best: it matches the register width, so the compiler needs no extra sign- or zero-extension instructions (UXTB/SXTH) after each increment. A uint8_t counter often produces more instructions because the compiler must wrap the value to 8 bits after every increment. Use narrow types for stored data (arrays, structure members, registers) where memory size matters, and register-width types for local temporaries.
Caveat: if you need wrap-around at a specific width (a ring-buffer index, a hardware counter model), use the fixed-width type deliberately and say so in a comment.
Study Plan: How to Use Your Score on These Data Types Interview Questions
Score
Meaning
Next step
90–100%
Excellent
Move on to Lesson 3.2: fixed-width integer types.
70–89%
Good
Redo Examples 1, 4, 6 and 9 on the examples page.
Below 70%
Revise
Re-read theory sections 4, 7 and 8, then retake this quiz.
Next lesson: After these data types interview questions, Lesson 3.2 solves the portability problem you just studied with uint8_t, uint16_t, uint32_t and the rest of <stdint.h>.
Lesson 3.1 complete!
Next up: fixed-width integer types from stdint.h and why every embedded project uses them.
2 Comments