Variables and Data Types in C

📘 C 👁 36 views 📅 Dec 22, 2025
⏱ Estimated reading time: 2 min

A variable is a named memory location used to store data that can be changed during program execution.


Rules for Naming Variables

  • Must begin with a letter or underscore _

  • Can contain letters, digits, and underscores

  • Cannot start with a digit

  • Cannot use C keywords

  • Case-sensitive

Valid: count, _total, sum1
Invalid: 1num, float, total-value


Declaration of Variables

int a; float b; char c;

Initialization of Variables

int a = 10; float b = 5.5; char c = 'A';

Types of Variables

  • Local Variables – Declared inside a function

  • Global Variables – Declared outside all functions

  • Static Variables – Retain value between function calls

  • Automatic Variables – Default local variables


Data Types in C

Data types specify the type of data a variable can store.


Classification of Data Types

1. Basic (Primary) Data Types

Data TypeDescription
intInteger values
floatDecimal values
doubleDouble precision decimals
charSingle character

2. Derived Data Types

  • Arrays

  • Pointers

  • Structures

  • Unions


3. Enumeration Data Type

enum day {Mon, Tue, Wed};

4. Void Data Type

  • Represents no value

void display();

Size of Data Types (Typical)

Data TypeSize
char1 byte
int2 or 4 bytes
float4 bytes
double8 bytes

Example Program

#include int main() { int age = 20; float salary = 25000.50; char grade = 'A'; printf("%d %.2f %c", age, salary, grade); return 0; }

Summary

  • Variables store data values

  • Data types define the kind of data

  • C supports multiple data types

  • Proper declaration is mandatory


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes