What is Function Pointer? Explain with example?

Answers were Sorted based on User's Feedback



What is Function Pointer? Explain with example?..

Answer / inderchauhan

A pointer is a special kind of variable in C and C++ that
holds the address of another variable.


my first pointer
#include <iostream>
using namespace std;

int main ()
{
int firstvalue, secondvalue;
int * mypointer;

mypointer = &firstvalue;
*mypointer = 10;
mypointer = &secondvalue;
*mypointer = 20;
cout << "firstvalue is " << firstvalue << endl;
cout << "secondvalue is " << secondvalue << endl;
return 0;
}



firstvalue is 10
secondvalue is 20

Is This Answer Correct ?    1 Yes 1 No

What is Function Pointer? Explain with example?..

Answer / sanjay bhosale

function pointer is simply a pointer which holds the address of the function so we can call that function by using pointer.
It is helpful in situations where we are required to pass the function pointer as parameter to some previously defined functions.
for e.g.
in comparison method we may pass function pointer for function which will compare 2 items/objects and help to comparison method.

Is This Answer Correct ?    0 Yes 0 No

What is Function Pointer? Explain with example?..

Answer / mahi

pointer is a variable witch can strore address of another
variable

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

You have an int array with n elements and a structure with three int members. ie struct No { unsigned int no1; unsigned int no2; unsigned int no3; }; Point1.Lets say 1 byte in the array element is represented like this - 1st 3 bits from LSB is one number, next 2 bits are 2nd no and last 3 bits are 3rd no. Now write a function, struct No* ExtractNos(unsigned int *, int count) which extracts each byte from array and converts LSByte in the order mentioned in point1.and save it the structure no1, no2, no3. in the function struct No* ExtractNos(unsigned int *, int count), first parameter points to the base address of array and second parameter says the no of elements in the array. For example: if your array LSB is Hex F7 then result no1 = 7, no2 = 2, no3 = 7. In the same way convert all the elements from the array and save the result in array of structure.

2 Answers   Qualcomm,


define c

6 Answers   HCL, TCS,


what is the full form of c language

9 Answers   Satyam, TCS, VNC,


For what purpose null pointer used?

0 Answers  


Explain how can you tell whether a program was compiled using c versus c++?

0 Answers  






which of 'arrays' or 'pointers' are faster?

5 Answers  


What is call by value in c?

0 Answers  


What is data structure in c programming?

0 Answers  


which will return integer? a) int*s ( ) b) ( int* ) s( ) c) int ( *s ) ( )

1 Answers   C DAC,


Stimulate calculators to perform addition,subtraction,multiplication and division on two numbers using if/else statement?

1 Answers   IBM,


Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?

7 Answers  


How can I recover the file name given an open stream?

0 Answers  


Categories