Data types in C


DATA TYPES

The data type, of a variable determines a set of values that a variable might take and a set of operations

that can be applied to those values. Data type refer to the type and size of data associated with the variable

and functions.

C language supports 2 different type of data types





1. Primary data types:

These are fundamental data types in C namely integer(int), floating point(float), character(char) and

void.

2. Derived data types:

Derived data types are nothing but primary data types but a little twisted or grouped together like array,

structure, union and pointer.


INTEGER TYPE

● Integer data type allows a variable to store numeric values.

● “int” keyword is used to refer integer data type.

● The storage size of int data type is 2 or 4 or 8 byte.

● It varies depend upon the processor in the CPU that we use. If we are using 16 bit processor, 2 byte

(16 bit) of memory will be allocated for int data type.

● Likewise, 4 byte (32 bit) of memory for 32 bit processor and 8 byte (64 bit) of memory for 64 bit

processor is allocated for int datatype.

● int (2 byte) can store values from -32,768 to +32,767

● int (4 byte) can store values from -2,147,483,648 to +2,147,483,647.

● If you want to use the integer value that crosses the above limit, you can go for “long int” and “long

long int” for which the limits are very high.

Example

0,8,-5


FLOATING POINT TYPE

● float or double variable type is used to store decimal values or real number values.

● floating point is denoted by float keyword in C

● The storage size of the floating point is 4 bytes but it depends upon the platform of the system.

● float data type is used to declare decimal numbers(no whole value) that can have positive and

negative value

Example

23.34, -5.34


char- Character types

● char variable is used to declare and store character type variables.

● the character is denoted by char keyword

● it used to store only one character using the char data type

Example

‘A,’, ‘c’

Void – void data type

● Void is a data type(it is also keyword) means No value or nothing. it is mostly used in function

identification for not return anything.

● You can not create a variable as void type


DERIVED DATA TYPES

Derived Data Types

Array, pointers, struct, and union are the derived data types in C.

Array:

Array in C stores multiple values of the same data type. That means we can have an

array of integers, chars, floats, doubles, etc

Pointers:

Pointers are considered by many to be complex in C, but that is not the case. Simply put,

a pointer is just a variable that stores the address of another variable. A pointer can store the

address of variables of any data types. This allows for dynamic memory allocation in C.

Pointers also help in passing variables by reference. The pointer is defined by using a

‘*’operator.

Structure

A struct is a composite structure that can contain variables of different data types. For

example, all the student data that we declared earlier in basic data types can be put under one

structure. Instead of having the information scattered, when we give it a structure, it is easier to

store information about more students.

Union

With a union, you can store different data types in the same memory location. The union

can have many members, but only one member can have a value at one time. Union, is thus, a

special kind of data type in C.

C KEYWORDS

Keywords are predefined, reserved words used in programming that have special

meanings to the compiler. Keywords are part of the syntax and they cannot be used as an

identifier.

A list of 32 keywords in the c language is given below:

auto            break            case         char        const         continue      default        do

double        else              enum        extern     float          for               goto            if

int               long             register     return     short          signed         sizeof         static

struct          switch          typedef     union     unsigned    void            volatile       while

Comments

Post a Comment

Popular posts from this blog

Storage Class