Search This Blog


Explain various types of data type in C Language?

  different types of data types,types of data type,explain data type,data types with examples,what are various data types,explain different types of data types with example, different types of data type,example of data types,what do you mean by data types, definition of data types in c language,definition of data types in c, explain data types in c language



Explain various Data Types in C Language?

Primary Data Type , Secondary Data Types, Floating Point Types, Character Types, An array in C, Structures, Pointers

1.    Explain various Data Types in C Language?

A C language programmer has to tell the system the type of numbers or characters he is using in his program. These are data types. There are many data types in C language. Data types are used to store various types of data.
C has a concept of 'Data types' which are used to define a variable before its use. C supports various data types such as character, integer and floating-point types.
All the data types are made up of units of memory called bytes.
In order of size, starting with the smallest, the integer types are char, short, int, longetc. The smaller types take less memory, the larger types takes more space in memory,.
C has different data types for different types of data and they are classified as:

I) Primary Data Type   II) Secondary Data Types

Primary Data Types:
I) Primary Data Type _____________________________

1. Integer Data Type:

Integers are whole numbers with a range of values,generally an integer occupies 2 bytes memory space and its value range limited to -32768 to +32768. To control the range of numbers and
storage space, C has three classes of integer storage namely short int, intand long int. All three data types
have signed and unsigned forms. Integer Data Types are denoted by int. 
Syntax For Integer Data Type
For Example :
short intb;
long intnum;
Memory Occupied By Integer :short int (1 Byte),int (2 Bytes),long int (4 Bytes) ____________________________________

a)    Long integer: long integer is a data type that can represent a whole number whose range is greater than or equal to that of a standard integer. The  range of long integer is -2147483648 to 2147483647.

Declaration of long int:longintcolor;    OR longcolor; _______________________________

b)   Short Integer:The range of short int is -32768 to -32767.'shortint' should assign less than or the same amount of storage as an 'int' and the 'int' should be less or the same bytes than a 'long int'. shortint must be at least 16 bits long.

Declaration of short int :shortintyellow; _______________________________

c)    Unsigned Integer: un signedint has a range of 0 - 65535. "int" can be negative, but "unsigned int" cannot be negative. %u Prints an unsigned integer. The size can range from 2 to 8, or (again) whatever the implementation provides.

Declaration of unsigned integer :unsignedintx;ORunsignedchargrey; ___________________________
d)   Signed Integer:%d Prints a signed integer. Range of signed int is -32768 to 32767.
Declaration of signed integer :signed inty; signed charwhite;

2. Floating Point Types:

The float data type is used to store fractional numbers (real numbers).
Floating point numbers are denoted by the keywordfloat. The double is same as float but it takes double space (8 bytes) than float.
Syntax For Floating Point Types: float ;
For Example:
float num1;
double num2;
long double num3;
Memory Occupied by Float:float (4 bytes),double (8 bytes),long double (10bytes) ____________________________________

3. CharacterTypes:

Character type variable can hold a single character. As there are singed and
unsigned int (either short or long), in the same way there are signed and unsigned chars; both occupy
 1 byte each, but having different ranges. Unsigned characters have values between 0 and 255; signed characters have values from –128 to 127. Character is declared by char
Syntax For Character Types: char;

For Example :
char ch='m';
char name='P';
Types built out of primitive data types - linked list, queue, stack, etc. ____________________________________

What Is Signed and Unsigned Char in C

C allows the character type char to be signed or unsigned, depending on the platform and compiler.With an unsigned char, the variable c takes the value 255, but with a signed char it becomes -1. If the signed or unsigned version of char is explicitly required at certain points in a program, it can be specified using the declarations signed char or unsigned char.

Declaration of signed and unsigned char:

unsigned char grey;signed char white; 


 II) Secondary Data Types

1. Arrays:
An array in C language is a collection ofsimilar data-type, means an array can hold value of a particular data type for which it has been declared. Arrays can be created from any of the C data-types int, float, and char. So an integer array can only hold integer values and cannot hold values other than integer.

Types of Arrays:

·         One Dimensional Array

·         Two Dimensional Array

·         Multi Dimensional Array

Declaration Of Arrays :

Syntax : type var_name[size];

2.Structures: We used variable in our C program to store value but one variable can store only single piece information (an integer can hold only one integer value) and to store similar type of values we had to declare many variables.

We used array which can hold numbers of similar data type. But array too have some limitations, like in our real world application we deal with set of dissimilar data types and single array cannot store dissimilar data.

For example: Think about storing book information or product information, a product can have different information to store like
Product code (an integer), product name (a char array), product price (a float) etc.
 And to store 20 products information we can declare integer array for product code, 2D character array for storing product name and float array to store product price. This approach definitely achieves your goals, but try to consider these things too. What if you wanted to add more products than 20, what if you want to add more information on products like stock, discount, tax etc? It will become difficult to differentiate these variables with other variables declared for calculation etc.
To solve this problem C language has a unique data type called Structure. C structure is nothing but collection of different related data types. If we are using C structure then we are combining different related data types in one group so that we can use and manage those variables easily. Here related data type means, a structure holding information about book will contains variable and array related to book.

Syntax for Structures:

For Example:
struct products
char name[20];
float price;
}; _________________________________

Pointers :In C a pointer is a variable that points to or references a memory location in which data is stored. By using the pointer we change the content of the memory location.

Pointer Declaration :A pointer is a variable that contains the memory location of another variable. The asterisk tells the compiler that you are creating a pointer variable. Finally we have to give the name of the variable.

Syntax For Pointers : 

Syntax : type * variable name;
For Example :
int*ptr; float *string

  different types of data types, types of data type, explain data type, data types with examples,what are various data types, explain different types of data types with example, different types of data type, example of data types,what do you mean by data types, definition of data types in c language, definition of data types in c, explain data types in c language

C Program example List