CPP C++ Certified Professional Programmer Exam, Exams of Technology

The CPP exam evaluates expertise in C++ programming. Candidates must demonstrate proficiency in the language's advanced features, such as object-oriented programming, memory management, and data structures. This certification is designed for professional programmers who write high-performance applications in C++ for software development, embedded systems, and more.

Typology: Exams

2024/2025

Available from 04/16/2025

nicky-jone
nicky-jone 🇮🇳

3.1

(39)

28K documents

1 / 53

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPP C++ Certified Professional Programmer Exam
Question 1: In C++, which of the following is not considered a fundamental built-in data type?
A) int
B) float
C) string
D) bool
Answer: C
Explanation: Although string is widely used in C++, it is provided by the Standard Template Library (STL)
rather than being a built-in primitive data type.
Question 2: What is the correct syntax to declare an integer variable named num in C++?
A) int num;
B) num int;
C) integer num;
D) var num;
Answer: A
Explanation: In C++, the declaration of a variable starts with the type followed by its name, so int num; is
correct.
Question 3: Which operator is used to access the address of a variable in C++?
A) *
B) &
C) %
D) $
Answer: B
Explanation: The ampersand (&) operator returns the address of its operand in C++.
Question 4: What will be the output of the following code snippet?
int a = 5, b = 2;
std::cout << a / b;
A) 2.5
B) 2
C) 3
D) 5/2
Answer: B
Explanation: Since both a and b are integers, integer division is performed, and 5/2 results in 2.
Question 5: Which of the following correctly defines a constant variable in C++?
A) const int num = 10;
B) int const num = 10;
C) Both A and B
D) int num = const 10;
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35

Partial preview of the text

Download CPP C++ Certified Professional Programmer Exam and more Exams Technology in PDF only on Docsity!

CPP C++ Certified Professional Programmer Exam

Question 1: In C++, which of the following is not considered a fundamental built-in data type? A) int B) float C) string D) bool Answer: C Explanation: Although string is widely used in C++, it is provided by the Standard Template Library (STL) rather than being a built-in primitive data type. Question 2: What is the correct syntax to declare an integer variable named num in C++? A) int num; B) num int; C) integer num; D) var num; Answer: A Explanation: In C++, the declaration of a variable starts with the type followed by its name, so int num; is correct. Question 3: Which operator is used to access the address of a variable in C++? A) * B) & C) % D) $ Answer: B Explanation: The ampersand (&) operator returns the address of its operand in C++. Question 4: What will be the output of the following code snippet? int a = 5, b = 2; std::cout << a / b; A) 2. B) 2 C) 3 D) 5/ Answer: B Explanation: Since both a and b are integers, integer division is performed, and 5/2 results in 2. Question 5: Which of the following correctly defines a constant variable in C++? A) const int num = 10; B) int const num = 10; C) Both A and B D) int num = const 10;

Answer: C Explanation: Both const int num = 10; and int const num = 10; are valid ways to define a constant in C++. Question 6: What is the output of the following loop? for (int i = 0; i < 3; i++) std::cout << i; A) 012 B) 123 C) 321 D) 0 1 2 Answer: A Explanation: The loop prints the numbers 0, 1, and 2 consecutively without any spaces. Question 7: Which operator is used for the modulus operation in C++? A) mod B) % C) // D) & Answer: B Explanation: The percent sign (%) is used to obtain the remainder of an integer division. Question 8: In C++, which control structure is best used for executing a block of code repeatedly until a condition is false? A) if-else B) switch C) for loop D) goto Answer: C Explanation: A for loop is typically used for executing code repeatedly as long as a specified condition holds true. Question 9: Which of the following is a valid relational operator in C++? A) <> B) == C) =! D) := Answer: B Explanation: The equality operator (==) is used to compare two values in C++. Question 10: Which of these is the correct syntax for a while loop in C++? A) while (condition) { // code } B) while { condition } ( // code ) C) while [condition] { // code } D) loop (condition) { // code }

Answer: C Explanation: The main() function is the designated entry point for any C++ program. Question 16: How is a single-line comment denoted in C++? A) // comment B) /* comment */ C) # comment D) -- comment Answer: A Explanation: Single-line comments in C++ begin with two forward slashes (//). Question 17: What will be the output of: std::cout << "Hello, " "World!"; A) Hello, World! B) Hello, World! C) Hello, "World!" D) An error Answer: A Explanation: Adjacent string literals in C++ are concatenated by the compiler into a single string. Question 18: Which operator has the highest precedence in C++? A) + B) * C) () (function call) D) = Answer: C Explanation: The function call operator and parentheses for grouping have high precedence in C++. Question 19: What does the expression 3 + 4 * 2 evaluate to in C++? A) 14 B) 11 C) 10 D) 16 Answer: B Explanation: Multiplication is performed before addition, so 4 * 2 is 8, and then 3 + 8 equals 11. Question 20: Which of the following is not a valid C++ identifier? A) value B) value C) 2value D) value Answer: C Explanation: Identifiers cannot begin with a digit in C++.

Question 21: Which arithmetic operator in C++ is used for exponentiation? A) ^ B) ** C) pow() function D) exp() function Answer: C Explanation: C++ does not have an exponentiation operator; instead, the pow() function from is used. Question 22: Which keyword is used to exit a loop immediately in C++? A) exit B) break C) stop D) return Answer: B Explanation: The break statement exits the nearest enclosing loop immediately. Question 23: How do you represent a character literal for the letter A in C++? A) "A" B) 'A' C) A D) A Answer: B Explanation: In C++, character literals are enclosed in single quotes. Question 24: Which of the following expressions correctly compares two values for inequality in C++? A) a <> b B) a != b C) a =! b D) a not b Answer: B Explanation: The != operator is used to check if two values are not equal in C++. Question 25: What is the purpose of the semicolon in C++ statements? A) It comments out code B) It separates multiple statements on one line C) It denotes the end of a statement D) It indicates a block of code Answer: C Explanation: The semicolon is used to mark the end of a statement in C++. Question 26: Which of the following correctly declares a function prototype for a function named add that takes two integers and returns an integer? A) int add(int, int);

Question 31: How are namespaces used in C++? A) To group related classes and functions to avoid name collisions B) To allocate memory dynamically C) To perform arithmetic operations D) To declare global variables Answer: A Explanation: Namespaces allow the grouping of related identifiers, which helps prevent naming conflicts in larger programs. Question 32: What does the 'using namespace std;' directive do in a C++ program? A) It imports the entire C++ standard library into the global namespace B) It limits the standard library usage to the std namespace C) It declares a new namespace called std D) It prevents access to the standard library Answer: A Explanation: The directive 'using namespace std;' allows direct access to all names in the std namespace without needing to prefix them with std::. Question 33: In which part of a C++ program is the function main() typically defined? A) Inside a class B) At global scope C) Within a namespace only D) Inside a header file Answer: B Explanation: The main() function is usually defined in the global scope and serves as the entry point of the program. Question 34: Which of the following statements about function declarations and definitions is true? A) A function can only be declared once B) A function definition must appear before its declaration C) A function declaration provides the interface, while the definition provides the implementation D) Function declarations are optional if the definition exists later in the code Answer: C Explanation: A function declaration informs the compiler about the function’s signature, whereas the definition contains the actual code. Question 35: What happens if you call a function without providing the required arguments and no defaults are set? A) The function uses random values B) The program compiles but gives undefined behavior C) A compile-time error occurs D) The function automatically assigns zero

Answer: C Explanation: C++ requires that the number and types of arguments match the function’s declaration; otherwise, a compile-time error occurs. Question 36: Which of the following is a valid signature for an overloaded function named display? A) void display(int); and void display(double); B) void display(int); and int display(int); C) void display(); and void display(); D) void display(int); and void display(int, int); Answer: A Explanation: Overloaded functions must differ in parameter types or numbers. Option A shows two functions with different parameter types. Question 37: How does a recursive function typically ensure termination? A) By using a loop inside the recursion B) By checking a base condition that does not call the function recursively C) By limiting the number of parameters D) By using a static counter Answer: B Explanation: A base condition that does not lead to further recursive calls is essential to prevent infinite recursion. Question 38: What is the purpose of function prototypes in header files? A) To define the full implementation of functions B) To allow code separation and reuse across multiple source files C) To create multiple definitions of the same function D) To restrict functions to a single file Answer: B Explanation: Function prototypes in header files allow functions to be declared once and used in multiple source files, promoting code reusability. Question 39: Which keyword is used to restrict the visibility of a function to a single translation unit? A) private B) static C) extern D) const Answer: B Explanation: Declaring a function as static within a source file limits its linkage to that file only. Question 40: What is the effect of the inline keyword on function calls in C++? A) It forces the compiler to optimize by inlining the function B) It always eliminates the function call overhead C) It suggests that the compiler replace the function call with the function code, but it is not mandatory D) It prevents recursion

C) A library that manages file access D) A type of exception handling Answer: A Explanation: Include guards prevent multiple inclusions of the same header file, avoiding redefinition errors. Question 46: Which of the following directives is used to start an include guard? A) #pragma once B) #include guard C) #ifndef D) Both A and C Answer: D Explanation: Both #pragma once and #ifndef (followed by #define) are common methods for implementing include guards. Question 47: What does the predefined macro FILE in C++ represent? A) The current date B) The current file name C) The current line number D) The current function name Answer: B Explanation: FILE expands to the name of the current source file in which it appears. Question 48: What is the purpose of the LINE macro in C++? A) To display the file name B) To output the current line number in the source code C) To declare a new line in the output D) To generate a unique identifier Answer: B Explanation: The LINE macro expands to the current line number in the source file. Question 49: Which directive is used to include the contents of one file into another at compile time? A) #import B) #include C) #using D) #define Answer: B Explanation: The #include directive is used to include the contents of another file during the preprocessing phase. Question 50: Which of the following is a valid use of conditional compilation? A) Compiling different code on Windows vs. Linux B) Running code faster

C) Automatically fixing syntax errors D) None of the above Answer: A Explanation: Conditional compilation allows different code to be compiled depending on the target operating system or environment. Question 51: Which of the following correctly declares an array of 10 integers in C++? A) int arr[10]; B) array<int,10> arr; C) int arr(); D) int arr = new int[10]; Answer: A Explanation: The syntax int arr[10]; is the standard way to declare an array of 10 integers in C++. Question 52: What is the correct way to access the third element of an array named data? A) data[2] B) data(3) C) data[3] D) data-> Answer: A Explanation: Array indexing in C++ is zero-based, so the third element is at index 2. Question 53: How are C-style strings represented in C++? A) As objects of the std::string class B) As arrays of characters terminated by a null character C) As linked lists of characters D) As pointers to integers Answer: B Explanation: C-style strings are represented as arrays of characters ending with a null terminator ('\0'). Question 54: Which header file is required to use the std::string class? A) B) C) D) <stdlib.h> Answer: B Explanation: The std::string class is defined in the header. Question 55: What does the term 'dynamic memory allocation' refer to in C++? A) Allocating memory at compile time B) Allocating memory on the stack C) Allocating memory during runtime using new and delete D) Allocating memory using arrays

Answer: B Explanation: In C++, a reference is an alias to an existing variable and cannot be null or reassigned once initialized. Question 61: How are type conversions typically handled in C++? A) Using implicit conversions only B) Through explicit casting operators such as static_cast and dynamic_cast C) By overloading the cast operator D) By redefining the data types Answer: B Explanation: C++ supports explicit type conversions using casting operators to ensure type safety during conversion. Question 62: Which of the following is a user-defined data structure in C++ that groups related variables? A) Array B) Structure (struct) C) Function D) Namespace Answer: B Explanation: A struct is a user-defined composite data type that groups variables under a single name. Question 63: What is a union in C++? A) A data structure that allows storing multiple data types in the same memory location B) A type of function overloading C) A method to combine two arrays D) A pointer to a structure Answer: A Explanation: A union is a special data type that allows storing different data types in the same memory location, though only one at a time. Question 64: Which of the following is true about the scope of a variable declared inside a function in C++? A) It is global B) It has block scope C) It is accessible outside the function D) It is a class member Answer: B Explanation: A variable declared inside a function has block scope, meaning it is only accessible within that function or block. Question 65: Which of these best describes the relationship between C and C++ in terms of data handling? A) C++ only supports new data structures and not the ones from C

B) C++ inherits many data handling features from C while adding its own object-oriented features C) C++ does not allow pointer usage unlike C D) C++ and C handle data in completely different ways Answer: B Explanation: C++ builds upon the C programming language, retaining its data handling capabilities while also introducing advanced features like object-oriented programming. Question 66: What is the primary purpose of a class in C++? A) To group related functions only B) To serve as a blueprint for creating objects C) To handle memory allocation D) To define global variables Answer: B Explanation: A class in C++ is a blueprint that defines the properties and behaviors (data members and member functions) of objects. Question 67: Which of the following is true about object instantiation in C++? A) Objects are only created dynamically B) Objects are instances of a class created at runtime C) Objects can only be created in the global scope D) Objects do not have constructors Answer: B Explanation: Objects are instances of classes that can be created either statically or dynamically during runtime. Question 68: What is the purpose of a constructor in a C++ class? A) To allocate dynamic memory B) To initialize an object's data members upon creation C) To destroy an object D) To overload operators Answer: B Explanation: A constructor is a special member function used to initialize objects of a class when they are created. Question 69: Which of the following correctly defines a destructor in C++? A) () C) destructor ClassName() D) void ~ClassName() Answer: A Explanation: The destructor is defined by preceding the class name with a tilde (~) and requires no return type. Question 70: Which concept of object-oriented programming involves restricting direct access to some of an object’s components?

Question 75: Which of the following is true regarding constructors in inheritance? A) Base class constructors are automatically called before derived class constructors B) Derived class constructors are called before base class constructors C) Constructors are not inherited D) Constructors must be explicitly called in every class Answer: A Explanation: In C++ inheritance, the base class constructor is automatically invoked before the derived class constructor. Question 76: Which operator can be overloaded as a member function in C++? A) :: B)? : C) + D) sizeof Answer: C Explanation: The + operator is one of the operators that can be overloaded as a member function in C++. Question 77: Which of the following is true about operator overloading in C++? A) You can create new operators B) You can change the precedence of operators C) You can define the behavior of an operator for user-defined types D) You can overload all operators including the scope resolution operator Answer: C Explanation: Operator overloading allows customizing the behavior of operators for user-defined types, but you cannot change operator precedence or create new operators. Question 78: What is the purpose of a copy constructor in a C++ class? A) To assign one object to another after they are created B) To initialize a new object as a copy of an existing object C) To convert an object to a primitive type D) To perform deep copying automatically Answer: B Explanation: The copy constructor is used to initialize a new object as a copy of an existing object. Question 79: What does the assignment operator (=) do in a class context? A) It initializes an object B) It assigns one object’s values to another already existing object C) It copies the constructor D) It defines the object’s destructor Answer: B Explanation: The assignment operator is used to copy values from one existing object to another. Question 80: Which of the following correctly declares a static data member in a C++ class? A) static int count;

B) int static count; C) count static int; D) static count int; Answer: A Explanation: Static data members are declared by placing the static keyword before the type within the class definition. Question 81: What is a pure virtual function in C++? A) A function with no implementation in a base class, making the class abstract B) A function that has a default implementation C) A function that can only be called by derived classes D) A function that overloads the virtual keyword Answer: A Explanation: A pure virtual function is declared by assigning 0 to it in the base class, making the class abstract and forcing derived classes to provide an implementation. Question 82: Which of the following statements about abstract classes is true? A) They cannot have any constructors B) They can be instantiated directly C) They contain at least one pure virtual function D) They do not support inheritance Answer: C Explanation: Abstract classes must contain at least one pure virtual function, which prevents direct instantiation of the class. Question 83: What is the primary benefit of operator overloading? A) It allows functions to be overloaded B) It enables user-defined types to interact with operators in a natural manner C) It improves the performance of the program D) It restricts the use of certain operators Answer: B Explanation: Operator overloading allows user-defined types to behave like built-in types by defining the behavior of operators for those types. Question 84: How does one define a copy constructor for a class named MyClass? A) MyClass(const MyClass& obj) B) MyClass(MyClass obj) C) MyClass& copy(const MyClass& obj) D) copy(MyClass& obj) Answer: A Explanation: The copy constructor is defined with a const reference parameter to avoid unnecessary copying and to allow copying of const objects.

Question 90: Which container is part of the C++ Standard Template Library (STL) for storing elements sequentially? A) std::vector B) std::map C) std::set D) std::queue Answer: A Explanation: std::vector is a dynamic array container that allows sequential storage of elements. Question 91: What is the purpose of an iterator in the STL? A) To perform arithmetic on containers B) To traverse elements of a container without exposing its underlying representation C) To manage memory allocation for containers D) To overload operators in containers Answer: B Explanation: Iterators provide a standard way to access and traverse elements of a container while abstracting the container’s structure. Question 92: Which of the following is a valid STL algorithm? A) sort() B) arrange() C) order() D) shift() Answer: A Explanation: The sort() algorithm is part of the STL and is used to arrange elements in a specified order. Question 93: How is exception handling implemented in C++? A) With if-else statements B) With try, catch, and throw blocks C) With error codes only D) With inline functions Answer: B Explanation: Exception handling in C++ is implemented using try blocks to enclose code that might throw an exception, catch blocks to handle exceptions, and throw statements to signal errors. Question 94: What does the throw keyword do in C++? A) It catches an exception B) It generates an exception C) It terminates the program D) It logs an error message Answer: B Explanation: The throw keyword is used to signal that an error or exceptional condition has occurred.

Question 95: What happens when an exception is thrown but not caught in C++? A) The program continues execution normally B) The program terminates C) The exception is ignored D) The exception is automatically handled Answer: B Explanation: If an exception is thrown and not caught by any catch block, the program terminates. Question 96: Which STL container is best suited for implementing a stack? A) std::vector B) std::deque C) std::stack D) std::list Answer: C Explanation: The std::stack container adapter is specifically designed for last-in-first-out (LIFO) data storage. Question 97: Which of the following is true about template classes in C++? A) They allow classes to operate with generic types B) They can only work with integer types C) They require virtual functions D) They must be defined in a separate source file Answer: A Explanation: Template classes enable the creation of generic classes that can work with any data type. Question 98: What is a common error when using templates in C++? A) Template instantiation conflicts B) Ambiguous operator overloading C) Memory leaks D) Incorrect exception handling Answer: A Explanation: Template instantiation errors can occur when the compiler is unable to deduce the correct type or when multiple template definitions conflict. Question 99: How are exceptions typically caught in C++? A) By reference to avoid slicing B) By value for simplicity C) Only by pointer D) Exceptions cannot be caught in C++ Answer: A Explanation: Catching exceptions by reference is preferred to avoid object slicing and to preserve polymorphic behavior.