Datatype in C

In C programming, data types define the nature of data that can be stored in a variable, determining both the kind of values it can hold and the amount of memory allocated for it. C offers several built-in data types categorized into basic, derived, and user-defined types.

Basic Data Types:
  1. int: Used for storing integers, typically occupying 4 bytes. Example: int age = 30;.
  2. float: Represents single-precision floating-point numbers, usually taking 4 bytes. Example: float salary = 50000.50;.
  3. double: For double-precision floating-point numbers, often using 8 bytes for greater accuracy. Example: double pi = 3.14159;.
  4. char: Holds a single character and usually occupies 1 byte. Example: char initial = 'A';.

Derived Data Types:
  • Arrays: Collections of similar data types, e.g., int numbers[5];.
  • Pointers: Variables that store memory addresses, e.g., int *ptr;.
  • Structures: Group different data types into a single unit, e.g., struct Person { char name[50]; int age; };.

User-defined Data Types:
  • Enumeration: Defines a set of named integer constants, enhancing code clarity.

Choosing appropriate data types is crucial for efficient memory management and accurate data representation in C programs.




  • To Share this Link, Choose your plateform


Our Other Tutorials