MCQsBasic MCQsintro-to-cppintro-to-cpp// C++ Introduction Quiz 1).What is the main purpose of the C++ programming language?1) To provide a platform-independent programming language for system and application software.2) To create web pages.3) To design graphics and animations.4) To simulate mathematical models in physics and engineering. 2).Which of the following is a valid C++ identifier?1) 123abc2) _myVariable3) int4) return 3).Which of the following is the correct syntax to include a header file in C++?1) #include <iostream>2) include iostream.h3) #include iostream4) #import <iostream> 4).Which of the following is the correct way to print 'Hello, World!' in C++?1) print("Hello, World!");2) echo "Hello, World!";3) cout << "Hello, World!";4) console.log("Hello, World!"); 5).What is the default value of a global variable in C++ if it is not explicitly initialized?1) 02) null3) undefined4) It throws an error. 6).Which operator is used to access members of a class in C++?1) .2) ->3) &4) * 7).In C++, which of the following types is used for dynamic memory allocation?1) new2) malloc3) alloc4) allocmem 8).Which of the following is the correct way to comment a single line in C++?1) // This is a comment2) /* This is a comment */3) <!-- This is a comment -->4) # This is a comment 9).Which of the following is the correct syntax to declare a constant in C++?1) const int x = 10;2) int x const = 10;3) constant int x = 10;4) x = const 10; 10).Which of the following statements is true about C++ functions?1) A function must always return a value.2) A function may or may not return a value.3) A function can only return an integer.4) A function cannot take parameters. 11). Which keyword is used to define a constant in C++?1) final2) const3) static4) immutable 12). What is the default value of a local variable in C++?1) 02) null3) undefined4) It throws an error. 13). Which of the following is used to declare a pointer in C++?1) &2) *3) ->4) % 14). What is the result of dividing two integers in C++?1) Float2) Integer division3) Error4) None of the above 15). Which of the following is a C++ data type?1) int2) string3) float4) All of the above 16). Which of the following is used for input in C++?1) cin2) input3) in4) printf 17). What is the syntax for a C++ comment?1) /* Comment */2) # Comment3) // Comment4) <!-- Comment --> 18). What is the correct way to declare an array in C++?1) int arr[10];2) arr int[10];3) int[10] arr;4) array arr(10); 19). Which operator is used to access a member of a class in C++?1) .2) ->3) &4) * 20). Which of the following is used to declare a constant in C++?1) const int x = 10;2) int x const = 10;3) constant int x = 10;4) x = const 10; 21). Which of the following is true about functions in C++?1) A function must always return a value2) A function can return no value (void)3) A function cannot take parameters4) A function can only return a string 22). Which of the following is used to include a standard library in C++?1) #import <iostream>2) #include <iostream>3) include <iostream>4) import <iostream> 23). Which of the following is a valid identifier in C++?1) 123abc2) _myVariable3) int4) return 24). Which operator is used to compare two values in C++?1) ==2) =3) ===4) != 25). Which of the following types is used for dynamic memory allocation?1) malloc2) alloc3) new4) allocmem 26). What is the size of an `int` in C++?1) 2 bytes2) 4 bytes3) 8 bytes4) 16 bytes 27). What does the `new` keyword do in C++?1) Allocates memory on the stack2) Allocates memory on the heap3) Creates a new function4) Creates a new class 28). Which of the following is the correct syntax for defining a function in C++?1) function_name() {}2) void function_name() {}3) def function_name() {}4) function function_name() {} 29). Which of the following is true about C++ classes?1) A class is a user-defined data type2) A class can contain only data3) A class can contain only functions4) None of the above 30). Which of the following is the correct way to declare a pointer in C++?1) int* ptr;2) ptr* int;3) int ptr;4) pointer int*; 31). Which operator is used for logical AND in C++?1) &2) &&3) |4) || 32). Which operator is used to check inequality in C++?1) !=2) !==3) !==4) == 33). What will the following code output?\n\n`int a = 5; int b = 10; cout << a + b;`1) 52) 103) 154) Error 34). How do you define a function in C++ that does not return any value?1) void function_name()2) function_name()3) void function_name(void)4) None of the above 35). Which of the following is the correct way to open a file in C++?1) fstream.open("file.txt")2) ifstream("file.txt")3) ofstream.open("file.txt")4) ifstream file.open("file.txt") 36). Which of the following is used to close a file in C++?1) file.close()2) close(file)3) fstream.close()4) None of the above 37). How can you initialize a constant in C++?1) const int a = 5;2) int const a = 5;3) Both of the above4) None of the above 38). Which of the following is used to define a constant pointer in C++?1) const int* ptr;2) int* const ptr;3) const int* const ptr;4) All of the above 39). Which of the following is the correct way to print to the console in C++?1) print("Hello World");2) printf("Hello World");3) cout << "Hello World";4) console.log("Hello World"); 40). What is a virtual function in C++?1) A function that can be called from any class2) A function defined with the `virtual` keyword3) A function that can only be accessed from base class4) None of the above 41). Which of the following is the correct way to call a base class function from a derived class in C++?1) base::function()2) super::function()3) this::function()4) base.function() 42). What is the output of the following C++ code?\n\n`int x = 10; cout << x++;`1) 102) 113) Error4) None of the above 43). Which of the following is the correct syntax for declaring a function pointer in C++?1) void (*func_ptr)();2) void func_ptr()3) func_ptr void ();4) None of the above 44). What is the purpose of the `const` keyword in function parameters in C++?1) To make sure the parameter is not modified2) To allow the function to modify the parameter3) To make the function parameter constant for any object4) None of the above 45). Which of the following is a feature of C++?1) Object-oriented programming2) Automatic garbage collection3) Multi-platform support4) All of the above 46). Which of the following is a correct way to allocate memory for an array of 10 integers in C++?1) int* arr = new int[10];2) int arr = new int[10];3) int arr[10] = new int;4) None of the above 47). Which of the following is the correct way to free memory allocated with `new`?1) free()2) delete()3) remove()4) dealloc() 48). Which of the following is used for exception handling in C++?1) try-catch2) throw-catch3) try-throw4) None of the above 49). Which of the following is the correct way to define a default constructor in C++?1) MyClass() {}2) MyClass(void) {}3) MyClass()4) All of the above 50). How do you define a class in C++?1) class MyClass {};2) class MyClass() {};3) MyClass class {};4) None of the above