- 1.1 History of Programming and Computer
- 1.2 History of C Programming Language
- 1.3 First C Program
- 1.4 Comments
- 1.5 Variables and Data Types
- 1.6 How to Take Input in C
- 1.7 Pre and Post Increment
- 1.8 Operator Precedence in C
- 2.1 Arithmetic Operators: +, -, *, /, %
- 2.2 Relational Operators: >, <, >=, <=, ==, !=
- 2.3 Logical Operators: &&, ||, !
- 2.4 If Else
- 2.5 If Else Ladder
- 2.6 Nested If Else
- 4.1 What is Array
- 4.2 Array Input and Output
- 4.3 Printing Reverse of an Array
- 4.4 Reverse Array Element (Two Pointers Technique)
- 4.5 Selection Sort
- 4.6 Sum of an Array
- 4.7 Counting Array
- 4.8 Sum of Two Values Equal x
- 4.9 Insert Element in Array
- 4.10 Remove Element from an Array
- 4.11 Array Concatenation
- 5.1 What is 2D Array
- 5.2 2D Array Input and Output
- 5.3 Print Specific Row and Column in 2D Array
- 5.4 Different Types of Matrix
- 6.1 What is String
- 6.2 String Input and Output
- 6.3 Length of a String
- 6.4 String Copy
- 6.5 String Lexicographical Comparison
- 6.6 String Concatenation
- 6.7 Counting/Frequency Problems
- 7.1 What is Function
- 7.2 Return + Parameter
- 7.3 Return + No Parameter
- 7.4 No Return + Parameter
- 7.5 No Return + No Parameter
- 7.6 Useful Built-in Function
- 7.7 Scopes in C
- 8.1 Call Stack
- 8.2 What is Recursion
- 8.3 Print 1 to 5 Using Recursion
- 8.4 Print 5 to 1 Using Recursion
- 8.5 Printing Array Using Recursion
- 8.6 Length of String Using Recursion
- 9.1 Pointers
- 9.2 Call by Value (Pass by Value)
- 9.3 Call by Reference (Pointer Dereferencing)
- 9.4 Array and Pointer Relationship
- 9.5 Pass Array into a Function
- 9.6 Pass String into a Function
- 1837 = Charles Babbage conceptualized and designed the Analytical Engine, the first mechanical general-purpose computer.
- 1843 = Ada Lovelace wrote an algorithm for the Analytical Engine. Her algorithms introduced foundational programming concepts such as loops, conditional branching, and the idea of data storage, earning her recognition as the world's first computer programmer.
- 1958 (AlGOL) = ALGOL (Algorithmic Language) was developed as a structured programming language, influencing the development of many modern languages, including C, particularly in concepts like block structure and nested functions.
- 1966 (BCPL) = BCPL (Basic Combined Programming Language) was developed for system-level programming. It influenced the creation of B, which was a direct precursor to C.
- 1070 (B) = B is a simpler version of BCPL. It was created at Bell Labs for early UNIX OS development but lacked essential data types and structures, which limited its ability to handle more complex software development.
- 1972 (C) = C was developed by Dennis Ritchie at Bell Labs to rewrite the UNIX operating system. Its design made it portable across different hardware platforms, and it became one of the most influential languages in software development.
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}After writing the program open vs code terminal and type:
-
Directives: Directives are special instructions for the preprocessor that start with a # symbol.
Some common directives:
#include= Includes the contents of another file into the current file, often used to include header files.#define= Define a macro.
-
Macros: Macros are special types of directives that allow you to define constants or reusable code snippets that defined using the #define directives.
example:
#include <stdio.h>
#define PI 3.1416
int main()
{
printf("Value of PI: %.4f", PI);
return 0;
}-
Preprocessor: Preprocessor is a tool or step in the compilation process that handles directives and macros before the actual compilation begins.
Key features of the preprocessor:
- It runs automatically before the compiler.
- It removes comments and expands macros.
What the Preprocessor Does:
- Reads the directives (Lines starting with
#) in the source code. - Modifies the code as per the directives and expands macros.
- Produces the preprocessed source code that is then passed to the compiler.
-
Header File: A header file in C is a file with a
.hextension that contains reusable code, such as function declarations, constants, variables, and data types. You can include it in your program using the#includedirective.Some Common Header Files in C:
stdio.h– Standard Input/Output functionsstdlib.h– Memory allocation, process control, conversionsmath.h– Mathematical functionsstring.h– String handling functionsstdbool.h– Boolean data type (true, false, bool)
-
main function(): The
main()function is the entry point of every C program. You must include themain()function once in your code for the program to work. No matter where you write themain()function, when the C program runs, it finds themain()function first and starts executing from there. -
printf() Function: The
printf()function is a predefined function. If you want to use this function, you have to include our standard input and output header or library file (stdio.h).
#include <stdio.h>
int main()
{
// This is a single line comment
/*
This is a
Multiline
Comment
*/
return 0;
}- int: - 4, -3, -2, -1 ,0 ,1 ,2 ,3 ,4 ---
%d(Format Specifier) - long long int: - 4, -3, -2, -1 ,0 ,1 ,2 ,3 ,4 ---
%lld - float: -4.53, -3.45, 1.5, 3.1416 ---
%f - double: -4.53, -3.45, 1.5, 3.1416 ---
%lf - char: ‘1’, ‘5’, ‘A’, ‘@’, ---
%c - bool: true(1) or false(0)
- Int = 10^9 = it allows up to approximately 10 digits
- long long int = 10^18 = it allows up to approximately 19 digits
- float = 10^6 = it allows up to approximately 7 digits precision (1.123456 = 7 digits)
- double = 10^14 = it allows up to approximately 15 digits precision
- char = -128 to 127
int a; int a = 30;a = 40;Note: initialization gives a variable its first value, while assignment gives a variable a new value after it has been initialized.
Example:
#include <stdio.h>
#include <stdbool.h>
int main()
{
int myInt = 2147483647;
long long int myLongLongInt = 9223372036854775807;
float myFloat = 1.123456;
double myDouble = 1.12345678912345;
char myChar = 'a';
bool myBool = true;
printf("myInt: %d\n", myInt);
printf("myLongLongInt: %lld\n", myLongLongInt);
printf("myFloat: %f\n", myFloat);
printf("myFloat: %.2f\n", myFloat);
printf("myDouble: %.15lf\n", myDouble);
printf("myChar: %c\n", myChar);
printf("myBool: %d\n", myBool);
return 0;
}#include <stdio.h>
int main()
{
int myInt;
float myFloat;
char myChar;
scanf("%d", &myInt); // & = address of operator or ampersand operator
scanf("%f", &myFloat);
scanf(" %c", &myChar); //The space before %c to consume any leftover newline character
printf("Integer: %d\n", myInt);
printf("Float: %f\n", myFloat);
printf("Float: %.2f\n", myFloat);
printf("Character: %c\n", myChar);
return 0;
}-
scanf()--printf() -
getchar()--putchar()=getchar()reads a single character, andputchar()prints a single character.
Code:
#include <stdio.h>
int main()
{
char myChar;
myChar = getchar();
putchar(myChar); // Output the character read from input
return 0;
}Note:
We cannot directly call the getchar() function. Instead, we must assign the getchar() function to a variable.
We are not allowed to add any additional text inside the putchar() function and The putchar() function must strictly be used to print a single character.
#include <stdio.h>
int main()
{
int i = 10;
int x = ++i;
// ------------->
printf("x = %d\n", x);
printf("i = %d", i);
return 0;
}Note:
Here, i is incremented to 11 first, and then this new value is assigned to x. Both i and x are 11 after this operation.
Post Increment
#include <stdio.h>
int main()
{
int i = 10;
int x = i++;
// ------------->
printf("x = %d\n", x);
printf("i = %d", i);
return 0;
}Note:
First, the value of i (which is 10) is assigned to the variable x. After that, i is incremented, so i becomes 11.
Note:
- Pre-increment (
++i): First increments the value ofi, then assigns it. - Post-increment (
i++): First assigns the value, then incrementsi.
So, if you write an expression like:
int result = 10 + 5 - 2 / 2 * 3;
Step-by-step evaluation:
10 + 5 – 1 * 3
10 + 5 – 3
15 – 3
12
Final result = 12








