The function pointer will point to which of the following?
(A) function
(B) constants
(C) variable
(D) absolute variables
Example of the Program in C++
#include <iostream>
using namespace std;
int Sum(int num1 , int num2)
{
return num1+num2;
}
int main()
{
int (*Function_Pointer)(int,int);
// function pointer declaration
Function_Pointer=Sum;
// Function_Pointer is pointing to the Sum function
int sum=Function_Pointer(3,4);
std::cout << "value of sum is:" <<sum<< std::endl;
return 0;
}
Output
value of sum is:7
Example of the Program in C
#include<stdio.h>
// function declaration
int Rectangle(int, int);
int main() {
int length, breadth, area;
int (*Area_function_pointer)(int, int);
printf("Enter the length and breadth of a rectangle\n");
scanf("%d%d", &length, &breadth);
// pointing the pointer to functions memory address
Area_function_pointer = Rectangle;
// calling the function using function pointer
area = (*Area_function_pointer)(length, breadth);
printf("Area of rectangle = %d", area);
return 0;
}
// function definition
int Rectangle(int x, int y) {
int area_of_rectangle = x * y;
return area_of_rectangle;
}
Output
Enter the length and breadth of a rectangle
6
7
Area of rectangle = 42
1000+ Programming C Plus Plus MCQs
Highly Recommended C++ Important MCQs with Explanation
- Which symbol is used to create multiple inheritances?
- If a derived class object is created, which constructor is called first?
- Which of the following is not a type of constructor?
- a ____ is a member function that is automatically called when a class object is __.
- What is the output of the following code in C++?
- How many times will the following code print?
- Which of the following is a procedural language?
- Which of the following is not a programming language?
- Which of the following is not an example of high-level language?
- While declaring pointer variables which operator do we use?
- To which does the function pointer point to?
- Which of these best describes an array?
- Which of the following is a Python Tuple?
Other important MCQs
Data Structure
Which of the following is not the type of queue?
Database
If one attribute is a determinant of the second, which in turn is a determinant of the third, then the relation cannot be
Python
Which of the following is a Python Tuple?