Quiz on AI Interviews Prep Live Training Corporate Training

Cpp Introduction.

1. What is C++?

C++ is a powerful, general-purpose programming language developed by Bjarne Stroustrup. It is widely used for system software, games, applications, and competitive programming.

2. Features of C++

  • Fast and efficient
  • Object-Oriented Programming (OOP)
  • Supports low-level memory manipulation
  • Portable and widely supported

3. Basic Structure of a C++ Program


#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!";
    return 0;
}
    

#include <iostream> – allows input/output
main() – starting point of program
cout – prints output

4. Variables and Data Types

Variables store data values.


int age = 18;
float height = 5.9;
char grade = 'A';
bool isStudent = true;
    
  • int – integer numbers
  • float – decimal numbers
  • char – single character
  • bool – true or false

5. Input and Output


#include <iostream>
using namespace std;

int main() {
    int number;
    cout << "Enter a number: ";
    cin >> number;
    cout << "You entered: " << number;
    return 0;
}
    

6. Conditional Statements

C++ uses conditions to make decisions.


int age = 20;

if (age >= 18) {
    cout << "Eligible to vote";
} else {
    cout << "Not eligible to vote";
}
    

7. Loops

Loops repeat a block of code.


// for loop
for(int i = 1; i <= 5; i++) {
    cout << i << " ";
}
    

// while loop
int i = 1;
while(i <= 5) {
    cout << i << " ";
    i++;
}
    

8. Functions

Functions are reusable blocks of code.


int add(int a, int b) {
    return a + b;
}
    

9. Arrays


int marks[5] = {80, 85, 90, 75, 88};

for(int i = 0; i < 5; i++) {
    cout << marks[i] << " ";
}
    

10. Object-Oriented Programming (OOP)

C++ supports OOP concepts:

  • Class
  • Object
  • Inheritance
  • Polymorphism
  • Encapsulation

class Student {
public:
    string name;
    int age;

    void display() {
        cout << name << " " << age;
    }
};
    

11. Applications of C++

  • Game development
  • Operating systems
  • Embedded systems
  • Competitive programming