What are the data types in C? Explain its types.


 In C programming language, there are several data types which can be broadly classified into two categories:

  1. Primitive Data Types
  2. Derived Data Types

Let's discuss each of them in detail:

  1. Primitive Data Types:

These data types are fundamental or basic data types which are directly supported by C. They are further classified into the following types:

a. Integer Data Type: Integer data type is used to store whole numbers, both positive and negative. There are four types of integer data types in C: char, int, short, and long. The size of these data types varies depending on the compiler and the platform.

b. Floating-point Data Type: Floating-point data type is used to store decimal numbers. There are two types of floating-point data types in C: float and double. The size of these data types also varies depending on the compiler and the platform.

c. Character Data Type: Character data type is used to store a single character. In C, character data type is represented by the keyword char.

d. Boolean Data Type: Boolean data type is used to store true or false values. In C, boolean data type is not directly supported. However, it can be represented using the keyword typedef and enum.

  1. Derived Data Types:

These data types are created by combining primitive data types. They are further classified into the following types:

a. Array Data Type: Array data type is used to store a collection of similar data types. In C, an array can be created by specifying the data type and the number of elements.

b. Pointer Data Type: Pointer data type is used to store the memory address of a variable. In C, a pointer can be created using the * operator.

c. Structure Data Type: Structure data type is used to store a collection of different data types. In C, a structure can be created using the keyword struct.

d. Union Data Type: Union data type is used to store different data types in the same memory location. In C, a union can be created using the keyword union.

e. Enumerated Data Type: Enumerated data type is used to create a set of named constants. In C, an enumerated data type can be created using the keyword enum.

These are the various data types in C programming language. Understanding them is crucial to write efficient and correct C programs.

Post a Comment

Previous Post Next Post