what is data type in c
Every programming language deals with some data. For example to print any message it requires charterer or string type of data. To solve any mathematics expression it requires integral as well as real number (floating type) of data. C is very rich in data type. Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that we use in our program. These data types have different storage capacities. Data types are used to define a variable before to use in a program. Size of variable, constant and array are determined by data types. There are four data types in C language.
C DATA TYPES:
Types:
Basic data types
Enumeration data type
Derived data type
Void data type
Data Types:
int, char, float, double
enum
pointer, array, structure, union
void
INTEGER DATA 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 bitprocessor, 2 byte (16 bit) of memory will be allocated for int data type. Like wise, 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.
FLOATING POINT DATA TYPE:
Floating point data type consists of 2 types. They are,
1. float
2. double
FLOAT
♦ Float data type allows a variable to store decimal values.
♦ Storage size of float data type is 4. This also varies depend upon the processor in the CPU as “int” data type.
♦ We can use up-to 6 digits after decimal using float data type.
♦ For example, 10.456789 can be stored in a variable using float data type.
DOUBLE
♦ Double data type is also same as float data type which allows up-to 10 digits after decimal.
♦ The range for double datatype is from 1E–37 to 1E+37
CHARACTER DATA TYPE
So far we have been looking on data types to store numbers, In programming we do need to store characters like a,b,c etc. For storing the character data C language provides char data type. By using char data type we can store characters in variables. While assigning a character value to a char type variable single quotes are used around the character as ‘a’.
♦ Character data type allows a variable to store only one character.
♦ Storage size of character data type is 1. We can store only one character using character data type.
♦ “char” keyword is used to refer character data type.
♦ For example, ‘A’ can be stored using char datatype. You can’t store more than one character using char data type.
Let’s take a look into different data types that the C language provides us to deal with whole numbers, real numbers and character data.
int - data type
int is used to define integer numbers.
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d",&number);
printf("Entered Number is = %d",number);
return 0;
}
Output
Enter an integer: 4
Entered Number is = 4
float - data type
float is used to define floating point numbers.
#include <stdio.h>
int main()
{
float f;
printf("Enter a number: ");
scanf("%f",&f);
printf("Value = %f", f);
return 0;
}
Output
Enter a number: 23.45
Value = 23.450000
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage for the number.
{
double atoms;
atoms = 2500000;
}
char - data type
#include <stdio.h>
int main()
{
char chr;
printf("Enter a character: ");
scanf("%c",&chr);
printf("You entered %c.",chr);
return 0;
}
Output
Enter a character: g
You entered g.
{
char letter;
letter = 'x';
}
0 মন্তব্য(গুলি):
একটি মন্তব্য পোস্ট করুন
Comment below if you have any questions