Back to course

Fundamental Data Types: Floating Point and Character

C Language: 0 to Hero - The Complete Beginner's Guide

Lesson 7: Fundamental Data Types: Floating Point and Character

Floating Point Types

Used for storing real numbers (numbers with a decimal point).

TypeDescriptionTypical Precision (Decimal Places)Typical Size (Bytes)
floatSingle precision6-74
doubleDouble precision (standard choice)15-168
long doubleExtended precisionUsually 18+10 or 12

c // Floating point examples float temperature = 25.5f; // 'f' suffix indicates float literal double pi = 3.1415926535; // Default floating-point literal is double

Character Type (char)

Used to store a single character (letters, digits, symbols). Characters are internally stored as their corresponding ASCII (or Unicode) integer values.

  • A char is usually 1 byte (8 bits).
  • It can be treated as a small integer (signed or unsigned).

c char grade = 'A'; // Single quotes for characters char newline = '\n'; // Storing an escape sequence

// Char treated as an integer char ascii_val = 65; // ASCII 65 is 'A'

sizeof() Operator

The sizeof() operator tells us how many bytes of memory a type or variable occupies. This is useful for understanding portability and memory usage.

c #include <stdio.h>

int main() { printf("Size of int: %zu bytes\n", sizeof(int)); printf("Size of double: %zu bytes\n", sizeof(double)); return 0; }

(Note: %zu is the format specifier for sizeof result.)