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.
Page Contents
Variable Declaration in C:
Here is the syntax that, how we can declare and initialize a 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.
| Type | Size (bytes) | Format Specifier | Description |
|---|---|---|---|
| int | at least 2, usually 4 | %d | Use to store negative and positive numbers. eg: 5,10,15 |
| char | 1 | %c | Use to store character. eg: ‘y’, ‘n’ |
| float | 4 | %f | Use to store decimal numbers. eg: 10.5 |
| double | 8 | %lf | Use to store decimal numbers. eg: 10.5 |
| short int | 2 | %hd | Use to store small negative and positive numeric values. |
| unsigned int | at least 2, usually 4 | %u | Use to store small only positive numeric values. |
| long int | at least 4, usually 8 | %li | Use to store both negative or positive large numeric values. |
| long long int | 8 | %lli | Use to store both negative or positive very large numeric values. |
| unsigned long int | 4 | %lu | Use to store both only positive large numeric values. |
| unsigned long long int | 8 | %llu | Use to store both only positive very large numeric values. |
| long double | 10,12,16 | %Lf | Use 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.
Parvesh Sandila is a results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
