C Programming · September 2, 2026

Practice Exercise Sheet: Data Types in C

Companion worksheet to “Data Types in C: Choosing the Right Box for Every Value” · Module I · Basics of C


📌 Before You Start

This worksheet has five parts, arranged from quick recall to full programs. Work through them in order — each part builds on ideas from the one before it. Try to answer every question without running a compiler first; the whole point is to test whether you can predict what C will do, not whether you can copy-paste and check. The answer key for Parts A–C is at the very end.

Contents


🔘 Part A — Multiple Choice

Choose the single best answer for each question.

1What is the minimum size the C standard guarantees for an int?Easy

  • A. 1 byte
  • B. 2 bytes
  • C. 4 bytes
  • D. 8 bytes

2Which type reliably holds around 15–16 significant digits?Easy

  • A. int
  • B. float
  • C. double
  • D. char

3Underneath, a char is actually stored as:Easy

  • A. A tiny piece of text
  • B. A small integer (its ASCII code)
  • C. A 1-bit flag
  • D. A pointer to a symbol table

4By default, numeric types like int are:Easy

  • A. unsigned
  • B. signed
  • C. Neither — you must always specify one
  • D. const

5What happens when -1 is assigned to an unsigned int?Medium

  • A. A compile-time error
  • B. It silently becomes 0
  • C. It wraps around to the largest possible unsigned value
  • D. It stores -1 anyway, ignoring unsigned

6Which format specifier does scanf require to read into a double variable?Medium

  • A. %f
  • B. %lf
  • C. %d
  • D. Either %f or %lf — they’re interchangeable in scanf

7Casting a float to an int, e.g. (int) 7.9, gives:Easy

  • A. 8 (rounds to nearest)
  • B. 7 (truncates)
  • C. A compile error
  • D. 0

8structunion, and enum belong to which category of data types?Medium

  • A. Basic (Primary)
  • B. Derived
  • C. User-Defined
  • D. Void

9What’s the most reliable way to find the exact size (in bytes) of a type on your specific system?Easy

  • A. Assume int is always 4 bytes
  • B. Check the compiler’s documentation only
  • C. Use the sizeof operator and print the result
  • D. Guess based on the variable’s name

10Which of these is not a basic (primary) data type in C?Easy

  • A. int
  • B. char
  • C. Array
  • D. float

🔍 Part B — Predict the Output

For each program, write down exactly what it prints — including spacing — before checking the answer key.

1Character arithmeticEasy

#include <stdio.h>

int main() {
    char c = 'm';
    printf("%d\n", c);
    return 0;
}

2Integer divisionMedium

#include <stdio.h>

int main() {
    int x = 15, y = 4;
    printf("%d\n", x / y);
    printf("%.2f\n", (float) x / y);
    return 0;
}

3Casting downEasy

#include <stdio.h>

int main() {
    double amount = 249.95;
    int rupees = (int) amount;
    printf("%d\n", rupees);
    return 0;
}

4Unsigned subtractionHard

#include <stdio.h>

int main() {
    unsigned int a = 3;
    unsigned int b = 5;
    printf("%u\n", a - b);
    return 0;
}

5Mixed-type expressionMedium

#include <stdio.h>

int main() {
    int quantity = 3;
    float unitPrice = 12.5;
    printf("%.1f\n", quantity * unitPrice);
    return 0;
}

6sizeof on an expressionMedium

#include <stdio.h>

int main() {
    char ch = 'X';
    printf("%zu\n", sizeof(ch));
    printf("%zu\n", sizeof(ch + 1));
    return 0;
}

💡 Hint: think about what type an arithmetic expression like ch + 1 promotes to, even though ch itself is a char.

7Char-to-char arithmeticMedium

#include <stdio.h>

int main() {
    char first = 'A';
    char last = 'E';
    printf("%d\n", last - first);
    return 0;
}

8Precision digitsMedium

#include <stdio.h>

int main() {
    float f = 1.0 / 3.0;
    double d = 1.0 / 3.0;
    printf("%.9f\n", f);
    printf("%.9lf\n", d);
    return 0;
}

💡 Hint: you don’t need the exact digits memorized — just describe correctly which line drifts from the true value first, and roughly where.


🐞 Part C — Find and Fix the Bug

Each program has exactly one bug related to data types. Identify what’s wrong, explain why it’s wrong, and write the corrected line.

1A percentage calculatorEasy

#include <stdio.h>

int main() {
    int marksObtained = 45;
    int totalMarks = 60;

    float percentage = marksObtained / totalMarks * 100;
    printf("Percentage: %.2f\n", percentage);

    return 0;
}

2Printing a priceEasy

#include <stdio.h>

int main() {
    float price = 349.50;
    printf("Price: %d\n", price);
    return 0;
}

3Counting downHard

#include <stdio.h>

int main() {
    unsigned int countdown = 3;

    while (countdown >= 0) {
        printf("%u\n", countdown);
        countdown--;
    }

    return 0;
}

💡 Hint: think about what countdown does the instant it would go below zero, and whether the loop condition can ever become false.

4Rounding a GPAMedium

#include <stdio.h>

int main() {
    double gpa = 8.97;
    int roundedGpa = (int) gpa;
    printf("Rounded GPA: %d\n", roundedGpa);
    return 0;
}

💡 Hint: the programmer’s comment (in their head) was “this rounds to the nearest whole number” — is that what actually happens?

5Reading a temperatureMedium

#include <stdio.h>

int main() {
    double temperature;
    printf("Enter temperature: ");
    scanf("%f", &temperature);
    printf("You entered: %.1lf\n", temperature);
    return 0;
}

💬 Part D — Short Answer

Answer in 2–4 sentences. There’s no single “correct wording” — focus on demonstrating the underlying idea clearly.

1What is the practical difference between float and double, and when would you deliberately choose one over the other?

2Explain why writing char letter = 'A'; letter = letter + 1; is valid C, even though letter is not declared as a numeric type.

3What is the difference between implicit conversion and explicit conversion (casting)? Give one example of each from the article.

4Why does casting a decimal value to an integer type truncate instead of round? What would you use instead if you actually needed rounding?

5Using the shipping-container analogy from the article, explain in your own words why forcing a double into an int “loses cargo.”

6Give one realistic scenario where using an unsigned int instead of a plain int would actually cause a bug, based on what you learned about wraparound.


💻 Part E — Programming Exercises

Write complete, compilable C programs for each of the following. Test them with more than one input where relevant.

1Type size reportEasy

Write a program that prints the size (in bytes) of charintfloatdoubleshort int, and long int — one per line, clearly labeled — using the sizeof operator.

2Average of three test scoresMedium

Write a program that declares three int test scores, calculates their average as a float, and prints it to 2 decimal places. Make sure you avoid the integer-division trap covered in the article.

3Temperature converter with castingMedium

Write a program that stores a temperature in Fahrenheit as a float, converts it to Celsius using the formula (F - 32) * 5 / 9, and prints both the precise decimal result and the result after casting it to an int — clearly labeling which is which.

4Simple Caesar shiftHard

Write a program that stores a single uppercase letter in a char variable and prints the letter that comes 3 positions later in the alphabet (so 'A' becomes 'D'), using character arithmetic — not a lookup table. You do not need to handle wraparound past 'Z'.

5Demonstrate wraparound yourselfHard

Write a program that declares an unsigned int, sets it to 0, subtracts 1 from it, and prints the result using %u. Add a comment above the print statement explaining, in your own words, exactly why the output is not -1.


🔑 Answer Key — Parts A, B, and C

Try every question yourself first. Part D and Part E are open-ended, so check those against the article’s explanations and your instructor’s feedback instead.

Part A — Multiple Choice

1B — 2 bytes. The C standard only guarantees int is at least 2 bytes; 4 bytes is typical but not guaranteed.

2C — double. float only reliably holds ~6–7 significant digits.

3B — A small integer (its ASCII code). Every character is secretly a number underneath.

4B — signed. Numeric types can represent negative values unless explicitly marked unsigned.

5C — It wraps around to the largest possible unsigned value (4294967295 for a typical 4-byte unsigned int).

6B — %lf. Unlike in printfscanf requires %lf for double%f and %lf are not interchangeable here.

7B — 7 (truncates). Casting chops off the decimal part rather than rounding.

8C — User-Defined. These are types you design yourself by combining other types.

9C — Use the sizeof operator and print the result. Sizes can legally vary between compilers and platforms.

10C — Array. Arrays are a derived type, built from a basic type — not basic themselves.

Part B — Predict the Output

1109 — the ASCII code for lowercase 'm'.

23 then 3.75 — the first line is plain integer division (truncated); the second casts x to float before dividing, giving the accurate result.

3249 — casting a double to int truncates; it never rounds up.

44294967294 — 3 - 5 = -2 mathematically, but stored in an unsigned int it wraps around to the maximum value minus 1.

537.5 — quantity (an int) is implicitly promoted to float before the multiplication, since it’s mixed with unitPrice.

61 then 4 (the second value depends on your compiler, but is never 1) — ch alone is 1 byte, but ch + 1 triggers integer promotion, so the expression’s type becomes int (typically 4 bytes) even though ch itself stays a char.

74 — 'E' is ASCII 69 and 'A' is ASCII 65; subtracting two chars gives their numeric difference, exactly like any other integer subtraction.

8The float line visibly drifts from the true repeating value 0.333333333... starting around the 7th digit; the double line stays accurate through all 9 printed digits — the same precision gap demonstrated with π in the article.

Part C — Find and Fix the Bug

1Bug: marksObtained / totalMarks performs integer division before the result is ever converted to float, so the decimal is lost immediately. Fix: float percentage = (float) marksObtained / totalMarks * 100;

2Bug: %d is used to print a float, which reads the value’s bits incorrectly and prints garbage. Fix: use %f (or %.2f) instead of %d.

3Bug: countdown is unsigned, so it can never be negative — the moment it would drop below 0, it wraps around to a huge positive number instead, so countdown >= 0 is always true and the loop never ends. Fix: declare countdown as a plain (signedint.

4Bug: (int) gpa truncates 8.97 down to 8, not 9 — casting never rounds. Fix: use round() from <math.h>, e.g. int roundedGpa = (int) round(gpa);

5Bug: temperature is a double, but scanf is using %f, which is only correct for a float in scanfFix: change the format specifier to %lf.