Datatypes in c

Datatypes in C

 Data types in c refer to an extensive system used for declaring variables or functions of different types.


Datatypes in c
Data types in c




The types in C can be classified as follows :−

1.Basic Types : These are the basic arithmetic types and are further classified into integer, float , double. 


Here are some common data types used in C:-

int

Integers are whole numbers that can have both zero, positive and negative values but no decimal values. 

Format specifier: %d

There can be short int, long int, unsigned and ...etc.

Example: int num;

Here num is a variable of type int which can store a integer value in it.

The size of the int data type can be 2, 4 and 8 byte, it depends on the computer system.

float and double

float and double are used to hold real numbers.

Format specifier: %f (for float)

Format specifier: %lf (for double)

Example:  float var;

Here var is a variable of type float which can store a floating point value in it(i.e decimal values).

Example:  double var;

Here var is a variable of type double which can store a floating point value with more precision in it(i.e decimal values).

basic data types in c
c data types


Difference between float and double:-

float is used for single precision and the size of the float is 4 byte where as double is used for double precision and the size is 8 byte.

char

Keyword char is used for declaring character type variables. It is used to store only a single character like 'a', 'b' ..etc.

Format specifier: %c

Example: char ch;

Here ch is a variable of type char where it can hold one character in it.

The size of the int data type is 1 byte, it depends on the computer system.

Boolean (or bool).

    • It is used where data is restricted to True/False or yes/no options. We can also say it as 1 for true and 0 for false. 
  • void

  • It is an incomplete data type. Void basically means  it does not have any type.
  • For example if the return type of the function is void that means it does not return any value.

  •  2. Derived Types:
  • These are the datatypes that are derived from the basic data types.
  • They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.

Other data types are:-

-Enumerated type

-Complex types

Post a Comment

0 Comments