🌟 C Programming Quick Revision – By Saksham Computers 🌟
C is a powerful procedural programming language. It is the base for many modern languages like C++, Java, etc. Perfect for learning logic building and programming fundamentals!
✅ 1️⃣ Basic Program
#include <stdio.h>
int main() {
printf("Hello, C!");
return 0;
}
🧮 2️⃣ Variables & Data Types
#include <stdio.h>
int main() {
int age = 20;
float salary = 15000.50;
char grade = 'A';
printf("Age: %d, Salary: %.2f, Grade: %c", age, salary, grade);
return 0;
}
➕ 3️⃣ Operators
#include <stdio.h>
int main() {
int a=10, b=5;
printf("a+b = %d\n", a+b);
printf("a==b? %d", a==b);
return 0;
}
🔄 4️⃣ Conditional Statements
if...else:#include <stdio.h>
int main() {
int n=7;
if(n>0)
printf("Positive");
else
printf("Non-positive");
return 0;
}
switch:
#include <stdio.h>
int main() {
int choice=2;
switch(choice) {
case 1: printf("One"); break;
case 2: printf("Two"); break;
default: printf("Other");
}
return 0;
}
🔁 5️⃣ Loops
for loop:#include <stdio.h>
int main() {
for(int i=1; i<=5; i++)
printf("%d ", i);
return 0;
}
while loop:
#include <stdio.h>
int main() {
int i=1;
while(i<=5) {
printf("%d ", i);
i++;
}
return 0;
}
📦 6️⃣ Functions
#include <stdio.h>
void greet() {
printf("Hello Students!");
}
int main() {
greet();
return 0;
}
🏷️ 7️⃣ Arrays
#include <stdio.h>
int main() {
int arr[3] = {10, 20, 30};
for(int i=0; i<3; i++)
printf("%d ", arr[i]);
return 0;
}
📚 8️⃣ Pointers
#include <stdio.h>
int main() {
int a=10;
int *p = &a;
printf("Value: %d, Address: %p", *p, p);
return 0;
}
📂 9️⃣ File Handling
#include <stdio.h>
int main() {
FILE *fp;
fp = fopen("demo.txt", "w");
fprintf(fp, "File content");
fclose(fp);
return 0;
}
📄 🔟 Structures
#include <stdio.h>
struct Student {
int roll;
char name[20];
};
int main() {
struct Student s = {101, "John"};
printf("Roll: %d, Name: %s", s.roll, s.name);
return 0;
}
✅ Conclusion:
C helps you build a strong programming base. Practice these short programs daily to master the logic!
✨ Keep coding! – Saksham Computers
🌟 C++ Quick Revision – By Saksham Computers 🌟
C++ is a powerful object-oriented programming language derived from C. It supports procedural, object-oriented, and generic programming. Perfect for beginners and professionals alike!
✅ 1️⃣ Basic Program
#include <iostream>
using namespace std;
int main() {
cout << "Hello, C++!" << endl;
return 0;
}
🧮 2️⃣ Variables & Data Types
#include <iostream>
using namespace std;
int main() {
int age = 20;
float salary = 15000.50;
char grade = 'A';
cout << "Age: " << age << ", Salary: " << salary << ", Grade: " << grade << endl;
return 0;
}
➕ 3️⃣ Operators
int a=10, b=5;
cout << "a+b = " << a+b << endl;
cout << "a==b? " << (a==b);
🔄 4️⃣ Conditional Statements
if...else:int n=7;
if(n>0) cout << "Positive";
else cout << "Non-positive";
switch:
int choice=2;
switch(choice) {
case 1: cout<<"One"; break;
case 2: cout<<"Two"; break;
default: cout<<"Other";
}
🔁 5️⃣ Loops
for loop:for(int i=1; i<=5; i++)
cout<<i<<" ";
while loop:
int i=1;
while(i<=5) {
cout<<i<<" ";
i++;
}
📦 6️⃣ Functions
void greet() {
cout<<"Hello Students!";
}
int main() {
greet();
return 0;
}
🏷️ 7️⃣ Arrays
int arr[3] = {10, 20, 30};
for(int i=0; i<3; i++)
cout<<arr[i]<<" ";
📚 8️⃣ Classes & Objects
class Student {
public:
int roll;
void show() { cout<<"Roll: "<<roll; }
};
int main() {
Student s;
s.roll = 101;
s.show();
return 0;
}
🧰 9️⃣ Constructors
class Test {
public:
Test() { cout<<"Constructor called"; }
};
int main() {
Test t;
return 0;
}
🔄 1️⃣0️⃣ Polymorphism (Function Overloading)
void show(int a) { cout<<a; }
void show(string s) { cout<<s; }
int main() {
show(100);
show("Hello");
return 0;
}
🧬 1️⃣1️⃣ Inheritance
class Base {
public:
void display() { cout<<"Base"; }
};
class Derived : public Base {};
int main() {
Derived d;
d.display();
return 0;
}
📂 1️⃣2️⃣ File Handling
#include <fstream>
using namespace std;
int main() {
ofstream fout("demo.txt");
fout << "File content";
fout.close();
return 0;
}
✅ Constructor:
✅ Example 1: Default Constructor
✅ Example 2: Parameterized Constructor
✅ Example 3: Constructor Overloading
✅ Example 4: Copy Constructor
🌟 Polymorphism in C++ (बहुरूपता)
Definition (व्याख्या):
Polymorphism is one of the fundamental concepts of Object-Oriented Programming (OOP). It means "many forms". In C++, polymorphism allows objects to behave differently based on their data type or class.
Types of Polymorphism:
-
Compile-time Polymorphism (Static binding)
-
Run-time Polymorphism (Dynamic binding)
✅ 1. Compile-time Polymorphism (Function Overloading & Operator Overloading)
📌 Function Overloading:
Multiple functions with the same name but different parameters.
📌 Operator Overloading:
✅ 2. Run-time Polymorphism (Using Inheritance and Virtual Functions)
📌 Example using Virtual Functions: