Programming Data Types
Data types are the keywords,
which are used for assigning a type to a variable.
Data types in C
Fundamental Data Types
·
Integer types
·
Floating Type
·
Character types
Derived Data Types
·
Arrays
·
Pointers
·
Structures
·
Enumeration
Syntax for declaration of a
variable data type variable name
1) Integer data types:-
Keyword int is used for
declaring the variable with integer type. For example:
int var1;
Here, var1 is a variable of
type integer.
The size of int is either 2
bytes or 4 bytes.
If you consider an integer
having size of 4 byte( equal to 32 bits),
2) Floating types:-
Variables of floating types
can hold real values(numbers) such as: 2.34, -9.382 etc. Keywords either float
or double is used for declaring floating type variable. For example:
float var2;
double var3;
Here, both var2 and var3 are
floating type variables.
In C, floating values can be
represented in exponential form as well. For example:
float var3=22.442e2
3) Character types
Keyword char is used for
declaring the variable of character type. For example:
char var4='h';
Here, var4 is a variable of
type character which is storing a character 'h'.
Size of data types
DataType
|
Storage size
|
Value range
|
char
|
1 byte
|
-128 to 127 or 0 to 255
|
unsigned char
|
1 byte
|
0 to 255
|
signed char
|
1 byte
|
-128 to 127
|
int
|
2 or 4 bytes
|
-32,768 to 32,767 or
-2,147,483,648 to 2,147,483,647
|
unsigned int
|
2 or 4 bytes
|
0 to 65,535 or 0 to
4,294,967,295
|
short
|
2 bytes
|
-32,768 to 32,767
|
unsigned short
|
2 bytes
|
0 to 65,535
|
long
|
4 bytes
|
-2,147,483,648 to
2,147,483,647
|
unsigned long
|
4 bytes
|
0 to 4,294,967,295
|
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
printf("value of int = %d",sizeof (x));
getch();
}
OUTPUT:-
Value of int = 2
// Write a program to find the size of char data type
#include<stdio.h>
#include<conio.h>
#include<limits.h>
void main()
{
char x;
printf("value of char=%d",sizeof (x));
getch();
}
OUTPUT:-
value of char = 1
No comments:
Post a Comment