Learn coding with amol

 Hello my name is amol sharma or vineet and this is my sixth part of learn coding with amol and in this part we are learning C++.

Let's Start 


Part-6 C++



πŸ’» Complete C++ Guide

This guide includes all important C++ topics with examples and explanations.

1. Hello World

Basic C++ program structure.

#include <iostream>

using namespace std;

int main() {

  cout << "Hello, World!";

  return 0;

}

2. Variables and Data Types

Declare and use variables with types.

int age = 13;

float pi = 3.14;

char grade = 'A';

string name = "Amol";

3. Input and Output

Using cin and cout for user interaction.

int num;

cout << "Enter number: ";

cin >> num;

cout << "You entered: " << num;

4. if / else Conditions

Control flow using conditionals.

int x = 20;

if (x > 10) {

  cout << "Greater than 10";

} else {

  cout << "10 or less";

}

5. Loops (for, while)

Execute a block multiple times.

for (int i = 0; i < 5; i++) {

  cout << i << endl;

}

int j = 0;

while (j < 5) {

  cout << j << endl;

  j++;

}

6. Functions

Create reusable blocks of code.

void greet() {

  cout << "Hello from function!";

}

int main() {

  greet();

  return 0;

}

7. Arrays and Vectors

Store multiple values.

int arr[3] = {1, 2, 3};

cout << arr[0];

#include <vector>

vector<int> v = {4, 5, 6};

cout << v[1];

8. Object-Oriented Programming (OOP)

Create classes and objects in C++.

class Person {

public:

  string name;

  int age;

  void greet() {

    cout << "Hello, " << name;

  }

};

int main() {

  Person p;

  p.name = "Amol";

  p.age = 13;

  p.greet();

  return 0;

}

9. Pointers

Store addresses of variables.

int x = 5;

int* ptr = &x;

cout << *ptr;

10. File Handling

Read/write files in C++.

#include <fstream>

ofstream file("data.txt");

file << "Hello File!";

file.close();
Report a Bug

🐞 Report a Bug

OR

Comments

Post a Comment

Popular posts from this blog

Learn coding with amol

Learn coding with amol