Datatypes:
Datatype of a variable specifies what type of data that is going to store in a variable and the amount of memory required (allocated) to store that variable. Datatypes are used to declare the variables i.e., intimate the compiler about a variable before using it in the program.Previous Topic:
Basic Datatypes in C:
Basic or primitive data types in C programming areint - For storing integer values
float - For storing real numbers
char - For storing a character
long - For storing integers (High range)
double - For storing real numbers(High Range)
Range of a datatype depends on the amount of memory allocated for a particular datatype. As C is a platform dependent language, memory allocated for each datatype depends on the compiler.We can know the amount of memory allocated for datatype by using sizeof operator.
char gets 1 byte of memory so range of char is -128 to 127
If 'n' bits are allocated for a variable then its range is from -2n-1 to 2n-1-1
There are some complex types in C such as structures,unions......
Program to know size of each Datatype:
#include<stdio.h>
void main()
{
printf("Memory allocated for int is %d bytes\n",sizeof(int));
printf("Memory allocated for float is %d bytes\n",sizeof(float));
printf("Memory allocated for char is %d bytes\n",sizeof(char));
printf("Memory allocated for double is %d bytes\n",sizeof(double));
printf("Memory allocated for long is %d bytes\n",sizeof(long));
printf("Memory allocated for short is %d bytes\n",sizeof(short));
}
0 comments:
Post a Comment