C Data Types

In C programming language, data types specify the type of data that a variable can hold. There are various data types available in C, which are broadly classified into two categories:

  1. Primary Data Types
  2. Derived Data Types

Let's see some examples of both primary and derived data types:

Primary Data Types

  1. int: The int data type is used to store integer values. It takes 2 or 4 bytes of memory depending on the compiler.
  2. char: The char data type is used to store a single character value. It takes 1 byte of memory.
  3. float: The float data type is used to store floating-point values. It takes 4 bytes of memory.
  4. double: The double data type is used to store double-precision floating-point values. It takes 8 bytes of memory.
  5. void: The void data type is used to specify that the function does not return any value.
     

Example:

int num = 10;

char ch = 'A';

float num = 3.14;

double num = 3.14159;

void printHello() {
  printf("Hello");
}

 

Derived Data Types

 

  1. Array: An array is a collection of similar data types stored in contiguous memory locations.
  2. Pointer: A pointer is a variable that stores the memory address of another variable.
  3. Structure: A structure is a user-defined data type that groups together variables of different data types.
  4. Union: A union is a user-defined data type that allows storing different data types in the same memory location.
  5. Enumeration: An enumeration is a user-defined data type that consists of a set of named integer constants.

Example:

int arr[5] = {1, 2, 3, 4, 5};

int num = 10;
int *ptr = #

struct employee {
  char name[50];
  int age;
  float salary;
};

union data {
  int num;
  char ch;
  float fnum;
};

enum weekDays {
  Monday,
  Tuesday,
  Wednesday,
  Thursday,
  Friday,
  Saturday,
  Sunday
};

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

64728