Opening Hours

Mon - Sat: 7AM - 7PM

C provides a variety of data types that you can use to declare variables. These data types determine the size and type of data that a variable can hold. Here are some common data types in C:

  1. int: Used for integer values. Typically, it has a size of 4 bytes.
    int age = 30;
  2. float: Used for single-precision floating-point numbers.
    float pi = 3.14159;
  3. double: Used for double-precision floating-point numbers, which have more precision than float.
    double pi = 3.14159265359;
  4. char: Used for individual characters. It typically has a size of 1 byte.
    char grade = 'A';
  5. short: Used for integers that don’t require as much storage as int. Typically, it has a size of 2 bytes.
    short temperature = 25;
  6. long: Used for integers that may require more storage than int. The size of long varies by platform but is typically larger than int.
    long population = 1000000L;
  7. long long: Used for very large integers. It is guaranteed to be at least 64 bits in size.
    long long bigNumber = 1234567890123456LL;
  8. unsigned: Used to declare unsigned integer types. These can only store positive values and have a larger range than their signed counterparts.
    unsigned int distance = 100;
  9. _Bool: Used for boolean values. It can hold either 0 (false) or 1 (true).
    _Bool isTrue = 1;
  10. Enum: An enumeration is a user-defined data type used to assign names to integral constants.
    enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
    enum Days today = Wednesday;
  11. Array: Arrays are collections of elements of the same data type.
    int numbers[5] = {1, 2, 3, 4, 5};
  12. Pointer: Pointers are used to store memory addresses. They don’t directly represent a data type but can point to variables of various data types.
    int x = 10;
    int *ptr = &x; // Pointer to an integer
  13. Struct: A struct is a user-defined composite data type that groups variables together under a single name.
    struct Point {
    int x;
    int y;
    struct Point p1 = {3, 4};
  14. Union: A union is similar to a struct, but it only occupies the memory required for the largest member, and all members share the same memory location.
    union Value {
    int intValue;
    float floatValue;
    union Value data;
    data.intValue = 42;

These are some of the most commonly used data types in C. Choosing the appropriate data type for your variables is important to ensure efficient memory usage and proper representation of your data.


Recommended Articles