C Programming Data Types
In this article, you will learn what is a datatype and some basic datatypes used in C programming.
Datatypes - Introduction
Datatypes are the declarations for variables. This determines the type of data and also the size of data associated with variables.
Data types specify what type of data we enter in a program. All the variables used in a C program must be declared with a datatype.
Datatypes in C are classified into
Primary datatypes
Primary datatypes are fundamental datatypes in C. They are integer, floating point, double float, character and void.
Data types and its key words:
- Integer int
- Character char
- Floating point float
- Double float double-
Derived datatypes
Derived datatypes are primary datatypes that are twisted or grouped together like an array, pointer,** structure** and union.
Some of the basic datatypes and their characteristics are described below.
Integer (int)
The datatype Integer holds the whole number. Example: int marks; Here, In marks, you can only store a value that is the whole number.
Floating point(float)
This is used to store the decimal number with single precision. Example: float percentage; This allows you to store value with decimal places.
Double(double)
This is used to store the decimal number with double precision.
Example: double average;
Character(char) It stores a single character and uses only a single byte of memory.
Example: char answer = ‘T’;
#include <stdio.h>
#include <limits.h>
int main()
{
int a=57;
char b = 'H';
float c = 57.57;
double d = 123.456789;
printf("Hey am an integer and my value is:%d \n",a);
printf("Hey am a character and my value is:%c \n",b);
printf("Hey am float and I hold %f as my value. \n",c);
printf("Hey am double data and I hold %d as my value. \n ",d);
return 0;
}
Output
Hey am an integer and my value is:57
Hey am a character and my value is:H
Hey am float and I hold 57.570000 as my value.
Hey am double data and I hold 2147483614 as my value.