Variable and DataTypes in C

By | May 4, 2020

In this tutorial, we will learn about Variable and DataTypes in C programming language. The main motive of variables is to store data in memory while the execution of a C program. The value of variables can be changed throughout the execution of the program and we change reuse variable any number of times throughout the program.

Variable Declaration in C:

Here is the syntax that, how we can declare variable in c program.

data_type variable_name = value;

Example Program:

#include <stdio.h>
int main () {

   /* declaring variable */
   int num1, num2;

   num1 = 10;
   num2 = 20;
  
   int ans = num1 + num2;
   printf("Ans : %d \n", ans);

   return 0;
}

Output:

Ans : 30

Data Types in C program:

Data Type determines the type and size of data associated with variables. There are several data types available in C language. It is important to note the size(storage capacity) of data types is different in different C compilers.

TypeSize (bytes)Format SpecifierDescription
intat least 2, usually 4%dUse to store negative and positive numbers. eg: 5,10,15
char1%cUse to store character. eg: ‘y’, ‘n’
float4%fUse to store decimal numbers. eg: 10.5
double8%lfUse to store decimal numbers. eg: 10.5
short int2%hdUse to store small negative and positive numeric values.
unsigned intat least 2, usually 4%uUse to store small only positive numeric values.
long intat least 4, usually 8%liUse to store both negative or positive large numeric values.
long long int8%lliUse to store both negative or positive very large numeric values.
unsigned long int4%luUse to store both only positive large numeric values.
unsigned long long int8%lluUse to store both only positive very large numeric values.
long double10,12,16%LfUse to store very large negative or positive decimal values.

Please keep continuing with our next tutorial in the next tutorial we will learn about Operators in C.