Code Sankalpa
C Language Fundamentals
📚

Select a Topic

Choose a subject from the left menu to start learning.

C Language Basics

Program for Problem Solving

C is a general-purpose programming language created by Dennis Ritchie at Bell Laboratories in 1972. It is a procedural language that provides low-level access to memory and is widely used for system-level programming.

Every C program starts execution from the main() function. Here is the most basic C program:

hello_world.c
// My first C program
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
Created by
Dennis Ritchie
Year
1972
Type
Procedural
C Language Basics

Introduction to Variables

A variable is a named memory location used to store data. In C, every variable must be declared with a data type before it is used.

Syntax: data_type variable_name = value;

variables.c
#include <stdio.h>

int main() {
    int   age    = 20;
    float marks  = 95.5;
    char  grade  = 'A';

    printf("Age: %d\n", age);
    printf("Marks: %.1f\n", marks);
    printf("Grade: %c\n", grade);
    return 0;
}
Rule
Declare before use
Scope
Local / Global
Storage
RAM (Stack)
C Language Basics

Data Types

Data types define the type and size of data a variable can hold. C has several built-in data types:

datatypes.c
int    a = 10;       // 4 bytes  → whole numbers
float  b = 3.14;    // 4 bytes  → decimal numbers
double c = 9.99;    // 8 bytes  → large decimals
char   d = 'A';     // 1 byte   → single character
void               // 0 bytes  → no value (functions)
int
4 bytes
float
4 bytes
double
8 bytes
char
1 byte
C Language Basics

Operators in C

Operators are symbols that perform operations on variables and values. C supports several categories of operators:

operators.c
// Arithmetic Operators
int a = 10, b = 3;
printf("%d\n", a + b);   // 13 → Addition
printf("%d\n", a - b);   // 7  → Subtraction
printf("%d\n", a * b);   // 30 → Multiplication
printf("%d\n", a / b);   // 3  → Division
printf("%d\n", a % b);   // 1  → Modulus

// Relational Operators
printf("%d\n", a == b);  // 0 (false)
printf("%d\n", a >  b);  // 1 (true)
Arithmetic
+ - * / %
Relational
== != > < >= <=
Logical
&& || !
Assignment
= += -= *=
C Language Basics

Control Structures

Control structures determine the flow of execution in a program. C supports three types: sequential, selection (if/switch), and iteration (loops).

control.c
// if-else
int marks = 75;
if (marks >= 50) {
    printf("Pass\n");
} else {
    printf("Fail\n");
}

// for loop
for (int i = 1; i <= 5; i++) {
    printf("%d ", i);
}
// Output: 1 2 3 4 5
Selection
if / else / switch
Iteration
for / while / do-while
Jump
break / continue