Bird
Raised Fist0
Embedded Cprogramming~20 mins

Fixed-width integers (uint8_t, uint16_t, uint32_t) in Embedded C - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Fixed-width Integer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of uint8_t overflow
What is the output of this C code snippet when using uint8_t for variable a?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    uint8_t a = 250;
    a += 10;
    printf("%u\n", a);
    return 0;
}
A4
B260
COverflow error at runtime
D10
Attempts:
2 left
💡 Hint
Remember that uint8_t can only hold values from 0 to 255 and wraps around on overflow.
❓ Predict Output
intermediate
2:00remaining
Size of fixed-width integers
What is the output of this code printing the sizes of uint8_t, uint16_t, and uint32_t in bytes?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    printf("%zu %zu %zu\n", sizeof(uint8_t), sizeof(uint16_t), sizeof(uint32_t));
    return 0;
}
A8 16 32
B4 4 4
C1 2 4
DCompiler dependent, could be any values
Attempts:
2 left
💡 Hint
Fixed-width integers have sizes guaranteed by their names.
🔧 Debug
advanced
2:00remaining
Unexpected output due to integer promotion
This code intends to add two uint8_t variables and print the result. What is the output and why?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    uint8_t x = 200;
    uint8_t y = 100;
    uint8_t z = x + y;
    printf("%u\n", z);
    return 0;
}
ACompilation error
B300
COverflow error
D44
Attempts:
2 left
💡 Hint
Remember that arithmetic on small integer types is promoted to int before assignment.
🧠 Conceptual
advanced
1:30remaining
Range of uint16_t
What is the range of values that a uint16_t variable can hold?
A0 to 32767
B0 to 65535
C-32768 to 32767
D-65535 to 65535
Attempts:
2 left
💡 Hint
uint16_t is unsigned and 16 bits wide.
❓ Predict Output
expert
2:30remaining
Bitwise operations on uint32_t
What is the output of this code snippet?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    uint32_t a = 0xF0F0F0F0;
    uint32_t b = 0x0F0F0F0F;
    uint32_t c = (a & b) | (~a & b);
    printf("0x%X\n", c);
    return 0;
}
A0x0F0F0F0F
B0xFFFFFFFF
C0xF0F0F0F0
D0x00000000
Attempts:
2 left
💡 Hint
Simplify the expression using bitwise logic identities.

Practice

(1/5)
1. What is the size in bits of the uint16_t type in embedded C?
easy
A. 64 bits
B. 8 bits
C. 32 bits
D. 16 bits

Solution

  1. Step 1: Understand the meaning of uint16_t

    The suffix 16_t means it uses 16 bits to store the number.
  2. Step 2: Confirm the size

    By definition, uint16_t is an unsigned integer type that uses exactly 16 bits.
  3. Final Answer:

    16 bits -> Option D
  4. Quick Check:

    uint16_t = 16 bits [OK]
Hint: Look at the number in the type name for bit size [OK]
Common Mistakes:
  • Confusing uint16_t with uint8_t
  • Thinking it stores 16 bytes instead of bits
  • Mixing signed and unsigned types
2. Which of the following is the correct way to declare a 32-bit unsigned integer variable named count?
easy
A. int32_t count;
B. uint32_t count;
C. uint16_t count;
D. int count32;

Solution

  1. Step 1: Identify the correct type for 32-bit unsigned integer

    uint32_t is the standard fixed-width unsigned 32-bit integer type.
  2. Step 2: Check the variable declaration syntax

    The syntax uint32_t count; correctly declares the variable count with that type.
  3. Final Answer:

    uint32_t count; -> Option B
  4. Quick Check:

    32-bit unsigned integer declaration = uint32_t count; [OK]
Hint: Use uint32_t for 32-bit unsigned integers [OK]
Common Mistakes:
  • Using signed type int32_t instead of unsigned
  • Using wrong bit size like uint16_t
  • Incorrect variable naming or syntax
3. What will be the output of this code snippet?
#include 
#include 

int main() {
    uint8_t a = 250;
    uint8_t b = 10;
    uint8_t c = a + b;
    printf("%u", c);
    return 0;
}
medium
A. 260
B. Overflow error
C. 4
D. 10

Solution

  1. Step 1: Understand the variable types and values

    a and b are uint8_t, which can hold values 0-255. a=250, b=10.
  2. Step 2: Calculate the sum and consider overflow

    Sum is 250 + 10 = 260. Since uint8_t max is 255, it wraps around modulo 256: 260 - 256 = 4.
  3. Final Answer:

    4 -> Option C
  4. Quick Check:

    260 mod 256 = 4 [OK]
Hint: Remember 8-bit max is 255; sums wrap around modulo 256 [OK]
Common Mistakes:
  • Expecting 260 as output ignoring overflow
  • Thinking it causes runtime error
  • Confusing signed and unsigned overflow behavior
4. Identify the error in this code snippet:
#include 

uint8_t x = 300;
medium
A. 300 is too large for uint8_t and causes overflow
B. Missing semicolon after declaration
C. uint8_t cannot be used without stdint.h
D. Variable name x is invalid

Solution

  1. Step 1: Check the value assigned to uint8_t

    uint8_t can only hold values 0 to 255. 300 is outside this range.
  2. Step 2: Understand the effect of assigning 300

    Assigning 300 causes overflow and the stored value wraps modulo 256, resulting in 44 (300 - 256).
  3. Final Answer:

    300 is too large for uint8_t and causes overflow -> Option A
  4. Quick Check:

    Value 300 > max 255 for uint8_t [OK]
Hint: Check if assigned value fits in the type's bit size [OK]
Common Mistakes:
  • Assuming compiler error instead of overflow
  • Ignoring the max value limit of uint8_t
  • Thinking variable name or syntax is wrong
5. You want to store the number 70000 in a fixed-width unsigned integer variable. Which type should you choose to avoid overflow?
hard
A. uint32_t
B. uint16_t
C. uint8_t
D. int16_t

Solution

  1. Step 1: Check the value range of each type

    uint8_t max is 255, uint16_t max is 65535, uint32_t max is 4294967295, int16_t max is 32767.
  2. Step 2: Find the type that can hold 70000

    70000 is greater than 65535 and 32767, so only uint32_t can hold it without overflow.
  3. Final Answer:

    uint32_t -> Option A
  4. Quick Check:

    70000 <= 4294967295 of uint32_t [OK]
Hint: Pick type with max value ≥ your number to avoid overflow [OK]
Common Mistakes:
  • Choosing uint16_t which is too small
  • Using signed types that have smaller max positive values
  • Ignoring overflow limits
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard