C Variables, Data Types & Constants Explained in Simple Tamil

C Variables, Data Types & Constants Explained in Simple Tamil | Tamil Technicians

Tamil Technicians – C Programming Course · Lesson 3

C Variables, Data Types & Constants Explained in Simple Tamil

In the previous lessons, we saw what programming is and the basic structure of a C program. Now we are going to learn one of the most important topics in C: variables, data types and constants. Simply said – “computer memory-la data eppadi store pannuvom?” nu paakkaporom.

C variables, data types and constants explained with simple icons – Tamil Technicians
Figure: Variables as labelled boxes in memory with different data types (int, float, char) and constants.

What Is a Variable in C?

In simple terms, a variable is a named storage location in memory. You can imagine it as a small labelled box where you can keep some value.

  • The name on the box is the variable name (like age, marks).
  • The type of the box tells what kind of data can be stored (integer, decimal, character, etc.).
  • The value inside the box is the current data stored in that variable.
Example
int age;      // Declare a variable named 'age' to store an integer
age = 25;     // Store the value 25 inside 'age'

Here, int is the data type, age is the variable name, and 25 is the value.

Declaration & Initialization of Variables

In C, when you create a variable, you must tell the compiler: “Intha peru-ku, intha type data store pannaporen”.

Declaration

int count;       // declares an integer variable
float price;     // declares a floating-point variable
char grade;      // declares a character variable

Initialization

Giving a starting value to a variable is called initialization.

int count = 10;
float price = 199.50;
char grade = 'A';

You can also declare multiple variables of the same type:

int a = 10, b = 20, c = 0;
float x = 1.5, y = 2.0;
Good practice: Always initialize variables before using them. Otherwise, they may contain garbage values (random data).

Rules for Variable Names in C

Variable names (identifiers) must follow some rules:

  • Can contain letters (A–Z, a–z), digits (0–9) and underscore _.
  • Cannot start with a digit. (e.g., 1age ❌, age1 ✅)
  • No spaces or special symbols like @, #, -, etc.
  • Case sensitive: age and Age are different.
  • Cannot use C keywords as variable names (like int, float, return).

Good Variable Name Examples

  • age, totalMarks, unit_price, solarVoltage

Bad Variable Name Examples

  • 2value (starts with number)
  • total price (space not allowed)
  • float (keyword)

Basic Data Types in C

A data type tells the compiler “intha variable-la eppadi data store panna poren?”. Different data types need different amount of memory and have different range of values.

Common Basic Data Types

Type Typical Size* Stores Example
int 4 bytes Whole numbers (no decimal) int age = 30;
float 4 bytes Decimal numbers (single precision) float temp = 32.5f;
double 8 bytes Decimal numbers (double precision) double price = 9999.99;
char 1 byte Single character char grade = 'A';

*Typical sizes on common 32/64-bit systems using GCC/Clang. Use sizeof to check exact size on your system.

Check Size
#include <stdio.h>

int main() {
    printf("Size of int = %zu bytes\\n", sizeof(int));
    printf("Size of float = %zu bytes\\n", sizeof(float));
    printf("Size of double = %zu bytes\\n", sizeof(double));
    printf("Size of char = %zu bytes\\n", sizeof(char));
    return 0;
}

int, float, double, char – With Simple Examples

int – Whole Numbers

int units = 350;
int year = 2025;

Used for counts, IDs, years, number of items, etc.

char – Single Character

char grade = 'B';
char answer = 'Y';

Always use single quotes ' ' and only one character.

float – Decimal (Approximate)

float voltage = 230.5f;
float current = 5.75f;

Use for sensor readings, temperatures, etc.

double – More Precision

double distance = 12345.6789;
double pi = 3.1415926535;

Use when you need more accurate decimal values.

Using printf & scanf With Data Types

#include <stdio.h>

int main() {
    int age;
    float temp;
    char grade;

    printf("Enter age: ");
    scanf("%d", &age);

    printf("Enter temperature: ");
    scanf("%f", &temp);

    printf("Enter grade (A/B/C): ");
    scanf(" %c", &grade);   // note the space before %c

    printf("Age = %d, Temp = %.2f, Grade = %c\\n", age, temp, grade);
    return 0;
}
Important: Use correct format specifiers: %d for int, %f for float, %lf for double, %c for char.

Type Modifiers – short, long, signed, unsigned (Basic idea)

C allows you to modify integer types with keywords like short, long, signed, unsigned.

  • short int – uses less memory, smaller range.
  • long int – uses more memory, larger range.
  • unsigned int – only positive values (and zero), but larger positive range.
short int smallCount;
unsigned int items;
long int bigNumber;

For now, as a beginner, using plain int is enough in most cases. Later, for embedded and optimization, we will see these in detail.

What Is a Constant in C?

A constant is a value that does not change while the program is running. Example: value of π (pi), fixed tax rate, maximum allowed items, etc.

There are three common ways of using constants in C:

  • Literal constants (direct values like 10, 3.14, 'A').
  • Symbolic constants using #define.
  • const keyword with variables.

Literal Constants

int days = 7;          // 7 is a literal integer constant
float pi = 3.14f;      // 3.14f is a float constant
char letter = 'A';     // 'A' is a character constant

Symbolic Constants with #define

#define PI 3.14159
#define MAX_STUDENTS  60

int main() {
    float radius = 5.0f;
    float area = PI * radius * radius;

    printf("Max allowed students = %d\\n", MAX_STUDENTS);
    printf("Area = %.2f\\n", area);
    return 0;
}

Here, PI and MAX_STUDENTS are symbolic names for constant values, replaced by the preprocessor before compilation.

Constants with const Keyword

const int MAX_SPEED = 120;
const float GST_RATE = 0.18f;

If you try to change a const variable later in the code, the compiler will give an error. This protects the value from accidental modification.

Variable vs Constant
  • Variable: value can change during execution (e.g., int count).
  • Constant: value is fixed (e.g., const float PI = 3.14f;).

Common Beginner Mistakes With Variables & Data Types

  • Using a variable without initializing it (random value problem).
  • Using wrong format specifier in printf/scanf (e.g., %d for float).
  • Overflow: storing a very large number in a small type (e.g., int x = 1000000000; on some systems).
  • Forgetting single quotes for char (writing char c = A; instead of 'A').

Quick Checklist Before Compiling

  • Did you choose correct data type for your values?
  • Are all variables declared before use?
  • Did you initialize variables with proper starting values?
  • Are format specifiers matching variable types?
  • Did you use const or #define for fixed values?

Suggested Featured Image Concept for This Post

For your blog thumbnail, you can design an image like this:

  • Three boxes labelled “int”, “float”, “char” with different values inside (e.g., 25, 99.5, ‘A’).
  • A separate box with a lock icon labelled “constant (const / #define)”.
  • A Tamil technician pointing at the boxes, with a big “C” logo on a laptop screen.
  • Top text: “C Variables & Data Types” and subtitle: “Explained in Simple Tamil”.

FAQ: Variables, Data Types & Constants in C

1. Which data type should I use most of the time?

For most counting and simple integer calculations, use int. For decimal values, use float or double. For single characters, use char.

2. When should I use double instead of float?

Use double when you need more precision (more correct decimal digits), like in scientific calculations or when rounding errors must be small.

3. Should I use #define or const for constants?

For simple numeric constants, both work. Modern C style prefers const for type safety (e.g., const int MAX = 10;), but #define is still common in old code and macros.

4. What happens if I don’t initialize a variable?

Local variables (inside functions) will contain garbage values (random data). This can cause wrong calculations and strange outputs. So always initialize variables before using them.

Category: C Programming Course · Lesson 3 – Variables, Data Types & Constants

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top