C Data Types and Format Specifiers

C data types determine what kind of value an object can store and how that value is interpreted. Common beginner types include char, signed and unsigned integer types, float, double and long double.

Common Data Types and Format Specifiers Top ↑

Declarationscanf()printf()
char c;scanf(" %c", &c);printf("%c", c);
int i;scanf("%d", &i);printf("%d", i);
unsigned int u;scanf("%u", &u);printf("%u", u);
short s;scanf("%hd", &s);printf("%hd", s);
unsigned short us;scanf("%hu", &us);printf("%hu", us);
long l;scanf("%ld", &l);printf("%ld", l);
unsigned long ul;scanf("%lu", &ul);printf("%lu", ul);
float f;scanf("%f", &f);printf("%f", f);
double d;scanf("%lf", &d);printf("%f", d);
long double ld;scanf("%Lf", &ld);printf("%Lf", ld);

Important: scanf() distinguishes %f for float * from %lf for double *. With printf(), a float argument is promoted to double, so %f is used for both float and double values.

Display Several Data Types Top ↑

#include <stdio.h>

int main(void) {
    int count = 10;
    float price = 5.25f;
    double distance = 10.123456;
    char grade = 'A';

    printf("Integer: %d\n", count);
    printf("Float: %.2f\n", price);
    printf("Double: %.6f\n", distance);
    printf("Character: %c\n", grade);
    return 0;
}

Output

Integer: 10
Float: 5.25
Double: 10.123456
Character: A

sizeof and Type Size Top ↑

printf("char: %zu bytes\n", sizeof(char));
printf("int: %zu bytes\n", sizeof(int));
printf("float: %zu bytes\n", sizeof(float));
printf("double: %zu bytes\n", sizeof(double));

sizeof returns a value of type size_t, so %zu is the matching printf() conversion. Except for char, exact byte sizes are implementation-dependent, so check them on the compiler/platform you are using.

const with Typed Objects Top ↑

const int max_items = 10;
const double tax_rate = 0.18;

See constants and variables in C for more examples.





plus2net.com






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer