Data Types in C

Data Types in C : Data type defines type of a data that can be stored in a variable. Data types in C are categorized as Buit-in data types, user-defined data types and derived data types. They are as follow :



  • Built-in Data Types / Basic Data Types :

Integer : Integer data type is used to store numerical values. Range for integer type values is -32768 to 32767. It requires two bytes memory for storing value. It can be further categorized as signed,  unsigned,  short and long. Range and memory requirements changes accordingly. For example 25, 100, 45 etc are integers


Character : Character data type is used to store any single character(letter, number or special symbol). The value of character is always enclosed in single quotation. It requires one byte memory per character to store value. For example 'H', 'i', '4' , '@' etc are characters.


Float : Float is used to stored floating point values. It ranges from 3.4 e -38 to 3.4 e +38. It requires four bytes of memory to store its value. Float can store values with maximum seven precision(maximum seven digits after floating point). For example 3.14, 2.56, 0.98 are float values.


Double : Higher precision values than floating point numbers can be stored using double data type. It ranges from 1.7 e -308 to 1.7 e +308. They can store about fourteen precision floating point numbers (fourteen digits after floating point). It requires eight bytes of memory to store its value.



  • User Defined Data Types  :
Structure : Structure in C can be defined by using struct keyword. Structure is a collection of different types of values. For example if want to store information about student like Roll number, name, class, percentage then it can be stored using structure. We will see it in detail in our Structure section.

Union : Union keyword is used to define union in C language. It is same as structure difference is union uses shared memory for storing values of union members. 

Enum : Enum is used to define enumerated data types. Enum keyword is used to define them. It is collection of key=value data pair. For example enum employee{"name"="Kunal","Address"="Pune"}. It is a special data type in C language.


  • Derived Data Types :
Array : An array is a collection  of different elements having a same data type (homogeneous elements). Array elements are allocated at contiguous memory locations.

Pointer : A pointer is a variable which stores address of another variable.

Function : A function is a named code of block used to define particular task.

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.