C - Data Types

Integer Types:

  • int: Used to store integers. Typical range is -32,768 to 32,767.
  • short: Used to store short integers. Typical range is -32,768 to 32,767.
  • long: Used to store long integers. Typical range is -2,147,483,648 to 2,147,483,647.
  • unsigned int: Used to store positive integers only. Typical range is 0 to 65,535.
  • unsigned short: Used to store positive short integers only. Typical range is 0 to 65,535.
  • unsigned long: Used to store positive long integers only. Typical range is 0 to 4,294,967,295.

Floating-Point Types:

  • float: Used to store single-precision floating-point numbers. Typically 4 bytes in size.
  • double: Used to store double-precision floating-point numbers. Typically 8 bytes in size.
  • long double: Used to store extended-precision floating-point numbers. Size can vary.

Character Types:

  • char: Used to store individual characters. Typically 1 byte in size.

Other Types:

  • void: Represents the absence of type. Used in function return types and pointers.

Format Specifiers for Integer Types:

  • %d: Used to print int.
  • %hd: Used to print short.
  • %ld: Used to print long.
  • %u: Used to print unsigned int.
  • %hu: Used to print unsigned short.
  • %lu: Used to print unsigned long.

Format Specifiers for Floating-Point Types:

  • %f: Used to print float.
  • %lf: Used to print double.
  • %Lf: Used to print long double.
  • Format Specifiers for Characters:
  • %c: Used to print char.

To set decimal precision for floating-point values when printing, you can use the format specifier along with a precision specifier. For example:

double num = 3.14159265359;
printf("%.2lf", num);  // Prints the value of num with 2 decimal places: 3.14

In this example, %.2lf specifies that the double value num should be printed with a precision of 2 decimal places.