Saturday 23 December 2017

Data Types in C Programming - Geeks4Coding

Data Types in C


All the variable in C has data type associated with it. Each variable require memory which depends on its data type and has some specific operations which can be performed over it. Let us briefly describe them one by one:

Following are the examples of some very common data types used in C:

char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.

int: As the name suggests, an int variable is used to store an integer.

float: It is used to store decimal numbers (numbers with floating point value) with single precision.

double: It is used to store decimal numbers (numbers with floating point value) with double precision.

Void: The type specifier void indicates that no value is available. This data type will be discussed in pointers section. Click here

Different data types also have different ranges upto which they can store numbers. These ranges may vary from compiler to compiler. Below is list of ranges along with the memory requirement and format specifiers on 32 bit gcc compiler.

We can use the sizeof() operator to check the size of a variable. See the following C program for the usage of the various data types:

#include <stdio.h>
int main()
{
int a = 1;
char b ='G';
double c = 3.14;
printf("Hello World!\n");
 

printf("%c and %lu byte.\n", b,sizeof(char));

printf("%d and %lu bytes.\n", a,sizeof(int));

printf("%lf and %lu bytes.\n",c,sizeof(double));

return 0;
}


Output:

Hello World!

G and 1 byte.
1 and 4 bytes.
3.140000 and 8 bytes.

No comments:

Post a Comment

Thank you for your Time. Keep Learning

Geeks4Coding

Contributors

Popular Posts