Test Series - cpp

Test Number 26/102

Q: What is the mandatory part to present in function pointers?
A. &
B. return values
C. data types
D. $
Solution: The data types are mandatory for declaring the variables in the function pointers.
Q: which of the following can be passed in function pointers?
A. variables
B. data types
C. functions
D. objects
Solution: Only functions are passed in function pointers.
Q: What is the meaning of the following declaration?

int(*ptr[5])();
A. ptr is pointer to function
B. ptr is array of pointer to function
C. ptr is pointer to such function which return type is array
D. ptr is pointer to array of function
Solution: In this expression, ptr is array not pointer.
Q: which keyword is used to define the macros in c++?
A. macro
B. define
C. #define
D. #macro
Solution: #define is the keyword which is used to define the macros in c++.
Q: Which symbol is used to declare the preprocessor directives?
A. #
B. $
C. *
D. ^
Solution: # symbol is used to declare the preprocessor directives.
Q: How many types of macros are there in c++?
A. 1
B. 2
C. 3
D. 4
Solution: There are two types of macros. They are object-like and function-like.
Q: What is the mandatory preprocessor directive for c++?
A. #define
B. #include
C. #undef
D. #macro
Solution: For a c++ program to execute, we need #include.
Q: What is the other name of the macro?
A. scripted directive
B. executed directive
C. link directive
D. executed & link directive
Solution: When the compiler encounters a previously defined macro, it will take the result from that execution itself.
Q: What will be the output of the following C++ code?

    #include 
    using namespace std;
    #define PR(id) cout << "The value of " #id " is "<
A. 10
B. 15
C. 20
D. 12
Solution: In this program, we are just printing the declared values.
Output:
$ g++ mac.cpp
$ a.out
10
Q: What will be the output of the following C++ code?

    #include 
    using namespace std;
    #define MAX 10
    int main()
    {
        int num;
        num = ++MAX;
        cout << num;
        return 0;
    }
A. 11
B. 10
C. compile time error
D. 13
Solution: Macro Preprocessor only replaces occurance of macro symbol with macro symbol value, So we can’t increment the value.

You Have Score    /10