Welcome to your C++ Level 2

1. 
What is the expected output of the following C++ code?

#include

int main() {

    int x = 5;

    int y = x++;

    std::cout << x << " " << y;

    return 0;

}

2. 
What is the expected output of the following C++ code?

#include

int main() {

    int x = 10;

    int y = ++x;

    std::cout << x << " " << y;

    return 0;

}

3. 
What is the expected output of the following C++ code?

#include

int main() {

    int x = 3;

    std::cout << (x << 2);

    return 0;

}

4. 
What is the expected output of the following C++ code?

#include

int main() {

    int x = 10;

    int y = 5;

    std::cout << (x % y);

    return 0;

}

5. 
What is the expected output of the following C++ code?

#include

int main() {

    int x = 5;

    int y = 2;

    std::cout << (x / y);

    return 0;

}

6. 
What is the expected output of the following C++ code?

#include

int main() {

    char str[] = "Hello, World!";

    std::cout << str[7];

    return 0;

}

7. 
What is the expected output of the following C++ code?

#include

int main() {

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

    std::cout << arr[3];

    return 0;

}

8. 
What is the expected output of the following C++ code?

#include

 

int main() {

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

    std::cout << arr[7];

    return 0;

}

9. 
What is the expected output of the following C++ code?

#include

int main() {

    int arr[5] = {0};

    std::cout << arr[2];

    return 0;

}

10. 
What is the expected output of the following C++ code?

#include

int main() {

    int arr[5];

    std::cout << arr[2];

    return 0;

}

11. 
What is the expected output of the following C++ code?

#include

int main() {

    int i = 0;

    while (i < 5) {

        std::cout << i << " ";

        i++;

    }

    return 0;

}

12. 
What is the expected output of the following C++ code?

#include

int main() {

    int i = 5;

    do {

        std::cout << i << " ";

        i--;

    } while (i > 0);

    return 0;

}

13. 
What is the expected output of the following C++ code?

#include

int main() {

    int i;

    for (i = 0; i < 3; i++) {

        std::cout << i << " ";

    }

    return 0;

}

14. 
What is the expected output of the following C++ code?

#include

int main() {

    int i;

    for (i = 0; i < 3; ++i) {

        std::cout << i << " ";

    }

    return 0;

}

15. 
What is the expected output of the following C++ code?

#include

int main() {

    int i;

    for (i = 1; i <= 5; i += 2) {

        std::cout << i << " ";

    }

    return 0;

}

16. 
What is the expected output of the following C++ code?

#include

int main() {

    int i;

    for (i = 5; i >= 0; i--) {

        std::cout << i << " ";

    }

    return 0;

}

17. 
What is the expected output of the following C++ code?

#include

int main() {

    int i;

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

        if (i == 3)

            continue;

        std::cout << i << " ";

    }

    return 0;

}

18. 
What is the expected output of the following C++ code?

#include

#include

int main() {

    std::vector vec = {1, 2, 3, 4, 5};

    for (int i : vec) {

        std::cout << i << " ";

    }

    return 0;

}

19. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::vector vec = {1, 2, 3, 4, 5};

    vec.pop_back();

    for (int i : vec) {

        std::cout << i << " ";

    }

    return 0;

}

20. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::vector vec = {1, 2, 3, 4, 5};

    vec.push_back(6);

    for (int i : vec) {

        std::cout << i << " ";

    }

    return 0;

}

21. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::vector vec = {1, 2, 3, 4, 5};

    vec.insert(vec.begin() + 2, 6);

    for (int i : vec) {

        std::cout << i << " ";

    }

    return 0;

}

22. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::string str1 = "Hello";

    std::string str2 = "World";

    std::string result = str1 + ", " + str2;

    std::cout << result;

    return 0;

}

23. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::string str = "Hello, World!";

    std::cout << str.length();

    return 0;

}

24. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::string str = "Hello, World!";

    std::cout << str[7];

    return 0;

}

25. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::string str = "Hello, World!";

    std::cout << str.find("World");

    return 0;

}

26. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::string str = "Hello, World!";

    str.replace(7, 5, "Universe");

    std::cout << str;

    return 0;

}

27. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::vector vec = {1, 2, 3, 4, 5};

    std::cout << vec.at(2);

    return 0;

}

28. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::vector vec = {1, 2, 3, 4, 5};

    vec.erase(vec.begin() + 2);

    for (int i : vec) {

        std::cout << i << " ";

    }

    return 0;

}

29. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::vector vec = {1, 2, 3, 4, 5};

    vec.push_back(6);

    for (int i : vec) {

        std::cout << i << " ";

    }

    return 0;

}

30. 
What is the expected output of the following C++ code?

#include

#include

 

int main() {

    std::vector vec = {1, 2, 3, 4, 5};

    vec.insert(vec.begin() + 2, 6);

    for (int i : vec) {

        std::cout << i << " ";

    }

    return 0;

}