Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — Data Types and Variables

Lesson 3 of 32 in the free C Language notes on Siksha Sarovar, written by Rohit Jangra.

Data Types and Variables in C

What is a Data Type?

A data type specifies the type of data a variable can hold, the amount of memory it occupies, and the operations that can be performed on it.

---

Primary (Built-in) Data Types

Data TypeSizeRangeFormat Specifier
int2 or 4 bytes-32768 to 32767 (2 bytes)%d
float4 bytes3.4e-38 to 3.4e+38%f
double8 bytes1.7e-308 to 1.7e+308%lf
char1 byte-128 to 127%c
void0 bytesNo value

---

Type Modifiers

Modifiers change the range or sign of basic data types:

ModifierExampleSizeRange
shortshort int2 bytes-32768 to 32767
longlong int4/8 byteswider range
unsignedunsigned int4 bytes0 to 65535
signedsigned int4 bytes-32768 to 32767

---

Variables

A variable is a named memory location that stores a value.

Syntax:

data_type variable_name;
data_type variable_name = value;  /* with initialisation */

Rules for variable names:

  • Must begin with a letter or underscore
  • Can contain letters, digits, underscores
  • Cannot use reserved keywords
  • Case-sensitive (ageAge)

Example:

#include <stdio.h>

int main() {
    int age = 20;
    float marks = 85.5;
    char grade = 'A';
    
    printf("Age: %d\n", age);
    printf("Marks: %.1f\n", marks);
    printf("Grade: %c\n", grade);
    
    return 0;
}

---

Constants

A constant is a value that cannot be changed during program execution.

#define PI 3.14159          /* macro constant */
const int MAX = 100;        /* const keyword */

---

Keywords in C

C89 has 32 reserved keywords:

auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while