C programming datatypes


C programming datatypes are names or labels which are used to define the kind of data being stored or manipulated. In any programming language, data type specifies the range of values that a variable can hold and how this information is stored in the memory heap.

c programming datatypes

Datatypes in C programming

Fundamental data types:
integer type
floating type
Character type
Derived data types:
Function
Arrays
Pointer
User-defined data types:
Structure
Union

Fundamental data types in C


Fundamental data types are basic built-in data types of C programming language. There are three fundamental data types in C programming. They are an integer data type, floating data type and character data type.

 Data type

Size(in bytes)

Range

 character 1 -128 to 127
 integer 2 -32,768 to 32,767
 floating 4 -3.4e-38 to 3.4e+38

Syntax for fundamental data types

int variable_name;     // keyword int is used for integer datatypes
float variable_name;    // keyword float is used for integer datatypes
char variable_name;     // keyword char is used for integer datatypes

Difference between float and double

float double
Floating-point number (i.e. a number containing decimal point or an exponent) Double-precision floating point number (i.e. more significant figures, and an exponent which may be larger in magnitude)
Size: 4 bytes Size: 8 bytes

Derived data types in C


Those data types which are derived from the fundamental data types are called derived data types. Function, arrays, and pointers are derived data types in C programming language.

For example, an array is derived data type because it contains the similar types of fundamental data types and acts as a new data type for C.

User defined data types in C


Those data types which are defined by the user as per his/her will are called user-defined data types. Examples of such data types are structure, union and enumeration.

For example, let’s define a structure

struct student
 {
  char name[100];
  int roll;
  float marks;
 }

Here, with this structure we can create our own defined data type in following way:

struct student info;

Here, student is user-defined data type where info is variable which holds name, roll number, and marks of a student.