Bird
Raised Fist0
Cprogramming~20 mins

Basic data types - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Basic Data Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of integer and float operations
What is the output of this C code snippet?
C
#include <stdio.h>
int main() {
    int a = 5;
    float b = 2.0;
    printf("%f", a / b);
    return 0;
}
A2
B2.000000
C2.500000
D0.000000
Attempts:
2 left
💡 Hint
Remember that dividing an int by a float results in a float.
❓ Predict Output
intermediate
2:00remaining
Size of data types
What will this program print?
C
#include <stdio.h>
int main() {
    printf("%zu", sizeof(char) + sizeof(int));
    return 0;
}
A4
B6
C8
D5
Attempts:
2 left
💡 Hint
On most systems, char is 1 byte and int is 4 bytes.
❓ Predict Output
advanced
2:00remaining
Unsigned integer overflow behavior
What is the output of this code?
C
#include <stdio.h>
int main() {
    unsigned int x = 0;
    x = x - 1;
    printf("%u", x);
    return 0;
}
ACompilation error
B4294967295
C-1
D0
Attempts:
2 left
💡 Hint
Unsigned integers wrap around on underflow.
❓ Predict Output
advanced
2:00remaining
Character and integer conversion
What does this program print?
C
#include <stdio.h>
int main() {
    char c = 'A';
    int i = c + 1;
    printf("%c %d", i, i);
    return 0;
}
AB 66
BA 65
CC 67
DCompilation error
Attempts:
2 left
💡 Hint
Characters are stored as numbers internally.
🧠 Conceptual
expert
2:00remaining
Behavior of signed integer overflow
What happens when a signed int variable in C overflows?
AIt causes undefined behavior according to the C standard.
BIt clamps to the maximum or minimum int value.
CIt wraps around like unsigned int, producing a defined value.
DIt triggers a runtime error automatically.
Attempts:
2 left
💡 Hint
Signed integer overflow is not defined by the C standard.

Practice

(1/5)
1. Which C data type is used to store whole numbers without decimals?
easy
A. int
B. float
C. char
D. bool

Solution

  1. Step 1: Understand data types for numbers

    Whole numbers without decimals are stored using the int type in C.
  2. Step 2: Identify correct type for whole numbers

    float stores decimals, char stores characters, and bool stores true/false values.
  3. Final Answer:

    int -> Option A
  4. Quick Check:

    Whole numbers = int [OK]
Hint: Whole numbers use int type in C [OK]
Common Mistakes:
  • Confusing float with int for whole numbers
  • Using char for numbers
  • Thinking bool stores numbers
2. Which of the following is the correct way to declare a variable of type float in C?
easy
A. int number = 3.14;
B. char number = 3.14;
C. float number = 3.14;
D. bool number = 3.14;

Solution

  1. Step 1: Check variable declaration syntax

    In C, to declare a float variable, use the keyword float followed by the variable name and value.
  2. Step 2: Match type with value

    Assigning 3.14 (a decimal) to a float variable is correct. Other types like int, char, or bool cannot hold decimal values properly.
  3. Final Answer:

    float number = 3.14; -> Option C
  4. Quick Check:

    Decimal numbers use float type [OK]
Hint: Use float keyword for decimal numbers [OK]
Common Mistakes:
  • Using int for decimal values
  • Assigning decimal to char
  • Using bool for numbers
3. What will be the output of this C code?
char letter = 'A';
int number = 5;
float decimal = 3.5;
printf("%c %d %.1f", letter, number, decimal);
medium
A. A 5 3
B. 65 5 3.5
C. A 5 3.50
D. A 5 3.5

Solution

  1. Step 1: Understand format specifiers

    %c prints a character, %d prints an integer, and %.1f prints a float with one decimal place.
  2. Step 2: Match variables to specifiers

    letter = 'A' prints 'A', number = 5 prints 5, and decimal = 3.5 prints 3.5 with one decimal.
  3. Final Answer:

    A 5 3.5 -> Option D
  4. Quick Check:

    Format specifiers match output [OK]
Hint: Match %c, %d, %.1f to char, int, float [OK]
Common Mistakes:
  • Printing char as int (shows ASCII code)
  • Ignoring decimal precision
  • Confusing format specifiers
4. Identify the error in this C code snippet:
bool flag = 1;
char letter = "B";
int count = 10;
medium
A. char should use single quotes for characters
B. bool cannot be assigned 1
C. int cannot be assigned 10
D. No errors, code is correct

Solution

  1. Step 1: Check bool assignment

    Assigning 1 to bool is allowed since 1 means true in C.
  2. Step 2: Check char assignment

    Characters must be in single quotes ('B'), not double quotes ("B") which are for strings.
  3. Final Answer:

    char should use single quotes for characters -> Option A
  4. Quick Check:

    char uses single quotes [OK]
Hint: Use single quotes for char, double for strings [OK]
Common Mistakes:
  • Using double quotes for char
  • Thinking bool can't be 1 or 0
  • Confusing int assignments
5. You want to store a student's grade as a letter (A, B, C, etc.) and whether they passed (true/false). Which data types should you use in C?
hard
A. int for grade, float for pass status
B. char for grade, bool for pass status
C. float for grade, int for pass status
D. bool for grade, char for pass status

Solution

  1. Step 1: Choose type for grade letter

    Grade letters like 'A' are single characters, so char is the right type.
  2. Step 2: Choose type for pass status

    Pass/fail is a true/false value, so bool fits perfectly.
  3. Final Answer:

    char for grade, bool for pass status -> Option B
  4. Quick Check:

    Letter = char, true/false = bool [OK]
Hint: Use char for letters, bool for true/false [OK]
Common Mistakes:
  • Using int or float for letter grades
  • Using char for true/false values
  • Mixing data types incorrectly
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