CodeBlanks Logo Icon CodeBlanks

Summary - Data types

Combine integer, floating-point and char types to write a calculation card.

Summary - Data types

In this group we covered the basic C data types:

  • Integers: int, short, long, unsigned
  • Decimals: float, double
  • Character: char (actually a small integer)
  • We measured type sizes with sizeof
  • We converted values with casts

Now solidify what you learned with two small tasks.

Practice Print the size of char

Write a C program: print sizeof(char) with printf using %zu. The output should be 1.

Sample solution

main.c
#include <stdio.h>

int main(void) {
    printf("%zu", sizeof(char));
    return 0;
}

Expected output

1

Practice Print int with cast

Write a C program: declare double pi = 3.14;, cast with (int) pi, and print it with printf and %d. The output should be 3.

Sample solution

main.c
#include <stdio.h>

int main(void) {
    double pi = 3.14;
    int i = (int) pi;
    printf("%d", i);
    return 0;
}

Expected output

3

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Match the core types

Term Meaning
int Integer
double Decimal
char Character
sizeof Size

2 Which takes 1 byte?

  • int
  • double
  • char Correct answer
  • long

Explanation: The char type is 1 byte.

All lessons in Beginner