Launch your tech mastery with us—your coding journey starts now!
Course Content
Introduction to C++ Programming
0/2
Control Flow Statements
Control flow statements in C++ allow the program to make decisions, repeat tasks, or jump to specific parts of code based on conditions. These statements give a program logical structure and control over the sequence of execution. Mastering control flow is essential for writing efficient and responsive programs. This section covers decision-making statements, looping constructs, and jump statements in detail with syntax and examples.
0/4
Functions in C++
Functions in C++ are blocks of reusable code designed to perform a specific task. They help break large programs into smaller, manageable pieces and improve readability, modularity, and reusability. Functions reduce code duplication by allowing programmers to call the same block of logic from multiple places. This modular approach also makes debugging easier and enhances program structure and clarity.
0/4
Modern C++ and Concurrency
0/2

Output-Based Questions

 

Q1.

#include<iostream>

using namespace std;

int main() {

    int x = 10, y = 5;

    cout << x++ << ” ” << ++y;

    return 0;

}

Output: 10 6

 

Q2.

#include<iostream>

using namespace std;

int main() {

    int a = 3;

    a += a++ + ++a;

    cout << a;

    return 0;

}

Output: 11

 

Q3.

#include<iostream>

using namespace std;

void test(int x) {

    if(x > 0) {

        test(–x);

        cout << x << ” “;

    }

}

int main() {

    test(3);

    return 0;

}

Output: 0 1 2

 

Q4.

#include<iostream>

using namespace std;

int main() {

    char c = ‘A’;

    cout << int(c) << ” ” << c + 1;

    return 0;

}

Output: 65 B

 

Q5.

#include<iostream>

using namespace std;

int main() {

    int arr[] = {10, 20, 30};

    cout << *(arr + 1);

    return 0;

}

Output: 20

 

Q6.

#include<iostream>

using namespace std;

int main() {

    int x = 5;

    cout << (x & 1);

    return 0;

}

Output: 1

 

Q7.

#include<iostream>

using namespace std;

void fun() {

    static int count = 0;

    count++;

    cout << count << ” “;

}

int main() {

    for(int i = 0; i < 3; i++) fun();

    return 0;

}

Output: 1 2 3

 

Q8.

#include<iostream>

using namespace std;

int main() {

    int x = 5;

    int &ref = x;

    ref++;

    cout << x;

    return 0;

}

Output: 6

 

Q9.

#include<iostream>

using namespace std;

int main() {

    string s = “Hello”;

    s += ” World”;

    cout << s;

    return 0;

}

Output: Hello World

 

Q10.

#include<iostream>

using namespace std;

int main() {

    int x = 7;

    cout << (x >> 1);

    return 0;

}

Output: 3

 

Q11.

#include<iostream>

using namespace std;

int main() {

    int x = 0;

    if (x = 5) cout << “True”;

    else cout << “False”;

    return 0;

}

Output: True

 

Q12.

#include<iostream>

using namespace std;

class A {

public:

    A() { cout << “A “; }

};

class B : public A {

public:

    B() { cout << “B “; }

};

int main() {

    B obj;

    return 0;

}

Output: A B

 

Q13.

#include<iostream>

using namespace std;

int main() {

    int a = 5, b = 2;

    cout << a / b << ” ” << a % b;

    return 0;

}

Output: 2 1

 

Q14.

#include<iostream>

using namespace std;

void swap(int &x, int &y) {

    int temp = x; x = y; y = temp;

}

int main() {

    int a = 5, b = 10;

    swap(a, b);

    cout << a << ” ” << b;

    return 0;

}

Output: 10 5

 

Q15.

#include<iostream>

using namespace std;

int main() {

    cout << sizeof(“Hello”);

    return 0;

}

Output: 6

 

Q16.

#include<iostream>

using namespace std;

int main() {

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

    cout << *(arr + 3);

    return 0;

}

Output: 4

 

Q17.

#include<iostream>

using namespace std;

int main() {

    string s = “abc”;

    s[0] = ‘z’;

    cout << s;

    return 0;

}

Output: zbc

 

Q18.

#include<iostream>

using namespace std;

int main() {

    int *p = NULL;

    cout << (p == 0);

    return 0;

}

Output: 1

 

Q19.

#include<iostream>

using namespace std;

class Test {

public:

    Test() { cout << “Constructor “; }

    ~Test() { cout << “Destructor”; }

};

int main() {

    Test t;

    return 0;

}

Output: Constructor Destructor

 

Q20.

#include<iostream>

using namespace std;

int main() {

    int a = 10;

    cout << (a > 5 ? “Yes” : “No”);

    return 0;

}

Output: Yes

 

Q21.

#include<iostream>

using namespace std;

int main() {

    int a = 1;

    for(int i = 0; i < 3; i++) a *= 2;

    cout << a;

    return 0;

}

Output: 8

 

Q22.

#include<iostream>

using namespace std;

int main() {

    char c = 65;

    cout << c;

    return 0;

}

Output: A

 

Q23.

#include<iostream>

using namespace std;

int main() {

    int x = 3;

    cout << (x << 2);

    return 0;

}

Output: 12

 

Q24.

#include<iostream>

using namespace std;

int main() {

    string str = “CPP”;

    cout << str.length();

    return 0;

}

Output: 3

 

Q25.

#include<iostream>

using namespace std;

int main() {

    bool b = 5 > 3;

    cout << b;

    return 0;

}

Output: 1