A Comprehensive Guide to Datatypes in C Programming

Datatypes in C

Datatypes represent the type of data stored in a variable.

Primary datatypes

These datatypes represent single value.It means they store only one value.

char:This datatype represents only one character, like N, n, 8 ,* ? etc.Char datatype takes only 1 byte of memory.

char ch;   /* declare char type variable ch */
ch='A'; /* store A into ch */

int:This datatype stores an integer number.It takes 2 bytes of memory.

int num;   /* declare num variable as int type */
num=5000; /* store 5000 into num */

float:This datatype represents a number with decimal point.Float takes 2 bytes of memory.

float sal;         /* declare sal as float type */
sal='78965.80'; /* store 78965.80 into sal */

double:This datatype represents a big flaot number.It takes 8 bytes of memory.

double speed;   /* declare speed as double type variable */
speed=3.14e8; /* store 3.1X10 power 8 into speed*/

void:It is a datatype but it is not used with a variable to store data.So, it is called ’empty datatype’.Generally it is used before a function to specify that the function does not return any value.

void myfunction()
{ statements; }

Here, myfunction() is the function name and void before it represents that this function will not return any result.Also, We can use void after the function name to specify that the function does not take any parameters.

int myfunction(void)
{ statements; }

Here, myfunction() returns int type result.myfunction(void) is not same as myfunction().

Data TypeRangeBytesFormat
signed char-128 to +1271%c
unsigned char0 to 2551%c
short signed int-32768 to +327672%d
short unsigned int0 to 655352%u
signed int-2147483648 to +21474836484%d
unsigned int0 to 42949672954%u
long singed int-2147483648 to +21474836484%lu
long unsigned int0 to 42949672954%lu
float-3.4e38 to +3.4e384%f
double-1.7e308 to +1.7e3088%lf
long double-1.7e4932 to +1.7e493210%lf

Table: Datatypes and their memory usage.

Naveed Tawargeri
 

Hi, I'm Naveed Tawargeri, and I'm the owner and creator of this blog. I'm a Software Developer with a passion for Programming.