You are on page 1of 5

WHAT IS DATA TYPE IN C?

Ans: Datatype is an entity that defines a set of values and a set of operations that can be
applied to those values. Data types are used to define a variable before to use in different.
The size of variable, constant and array are determined by data types.
Explain different data types used in C language?
Describe Basic four data types in a c programming language.
Explain primary data types used in C?
List and explain different data types with examples.
Write detailed notes on C data types.
What are the different data types available in C? Explain each one of them.
What is data type? Explain different types of data types in C.
Ans: Classification of Data types in C-Language: C programming is quite rich in its data types.
Generally, the data type is machine-dependent. C language is defined by ANSI (American
National Standard Institute). The data used are divided into four categories.
1. Basic or Primary or Fundamental data type
2. Derived data type
3.User-defined data type
4. Empty data type
BASIC/ PRIMARY DATA TYPES:
There are four types:
A. Integer data type(int):
An Integer Data Type is used to declare an integer type number (5.33, 76.99 etc). It
consumes 2 bytes of memory. This data ranges from -32768 to +32767. It can not be stored
in decimal numbers integers can be signed or unsigned. This data is often used in different
ways like - Short Integer, Long Integer, Signed, Unsigned Integer etc. The 'int' keyword is
used to declare integer variable. The format %d is used as a specifier for integer variables.
Syntax:
int <variable name>;
int num1;
short int num2;
long int num3;
Example
main ()
{
int p, q;
p = 6;
q= 5;
printf ("%d %d", p, q);
}
B. Floting point data type:
Float Data Type is used to declare decimal type of number (10.01, 12.13, 3.14 etc.). It is also
known as real data types. It data consume 4 bytes of memory. This data ranges from 3.4E-38
to 3.4E+38. The float variable can store values with 6 to 7 digit of precision. The 'float'
keyword is used to declare float variable. The format %f is used as a specifier for float
variables.
Syntax:
float <variable name>;
float num1;
double num2;
long double num3;
Example:
main ()
{
Float a, b, c;
a = 8.3;
b = 4.78;
c = a + b;
printf (“%f”, c);
}
C. Double data types: The double and float types are very similar. Double Data Type is used
to declare decimal number (3.141614161416, 2.91919293 etc.) It consume 8 bytes of
memory. It can store the range of values between -1.7E308 to 1.7E308. It can store the
range of valuewith 14 to 15 digit of precision. This data is often used in different ways like
double and long double. The 'double' keyword is used to declare double variable. The
format %lf is used as a specifier for double variables.
Syntax
double <variable name>;
double num1;
double num2;
Example
main ()
{
double a, b, c;
a = 5.673;
b=5.112;
c = a+b;
printf("%f", c):
}
D.Character data types
Generally character Data Type is used to declare a data in characte or string. It consume 1
bytes of memory.The qualifier signed or unsigned may be explicitly applied to char. While
unsigned chars have values between 0 and 255, signed chars have values from -128 to 127.
The data types which are used to store alphabet as well as all other 5 chacters belongs to
ASCII character set. The 'char' keyword is used to declare character variable. The format %c
is used as a specifier for character variables.
Syntex
char <variable name>;
char ch = ‘a’;
Example
main (

Char a;

a = 'b'; printf("%c", a);

2.DERIVED DATA TYPE


Those data types which are derived from fundamental data types are called derived data
types.There are basically three derived data types . Ther are four types – array,function,
pointer and structure data types.
3.USER-DEFINED DATA TYPE
Those data types which are defined by the user as per his/her will are called user-
defined data types. There are three types- structs, union and enumeration data
types.
4.EMPTY DATA TYPE: Empty data type is the one which has no value. Void is an
empty data type that has no associated value. The void is a data type which is
used to specify, return type of function or simply it has no return type. Void
means nothing.It is consume no memory
It can be used in functions and pointers. It also specifies that no argument is passd
by function.The keyword 'void' is used to specify void.
Example- Void display ()

DATA TYPE DECLARATION RULES


Data Type Declaration Rules in C Programming:
 The data type keyword must be entered to determine the data type before
declaring the variable. For example - int, float.
 Then write the name of the variable with a space. eg int sum;
 A semicolon should be given at the end. eg int sum;
 When declaring multiple variables of the same type, separate the variables
with a comma on the same line after the data type keyword, followed by a
semicolon. eg int n1, n2, sum; etc.
 The format specifier is used in the statement according to the declared
variable type.
Format:
<data type keyword > <variable name>;
or,
<data type keyword> <variable name1>, <variable name2>, <variable name1>;
Data types Keyword Example
Integer int Int num1;
int num1,num2;
Float float float x;
float a,b,c;
Double double double x;
double x,y,z;
Character char char a;
char a,b,c;

Difference between fundamental data types and derived data types.

Fundamental Data Types Derived Data Types

Fundamental data type is also called Derived data type is the


primitive data type. These are the basic data aggregation of
types. fundamental data type.

Pointers, arrays, structures


Character, integer, float, and void are and unions are derived
fundamental data types. data types.

Character is used for characters. It can be Pointers are used for


classified as char, Signed char, Unsigned storing address of
char. variables.
Fundamental Data Types Derived Data Types

Integer is used for integers( not having


decimal digits). It can be classified as signed Array is used to contain
and unsigned. Further classified as int, short similar type of data.
int and long int.

structure is used to group


float is used for decimal numbers. These are items of possibly different
classified as float, double and long double. types into a single type.

It is like structure but all


void is used where there is no return value members in union share
required. the same memory location

You might also like