What is Function Pointer? Explain with example?
Answers were Sorted based on User's Feedback
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 |
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 the difference between %d and %*d in C
What is the o/p of the follow pgm? #include<stdio.h> main() { char char_arr[5]=”ORACL”; char c=’E’; prinf(“%s\n”,strcat(char_arr,c)); } a:oracle b. oracl c.e d.none
How can you find the day of the week given the date?
Explain what is the use of a semicolon (;) at the end of every program statement?
Explain how do you override a defined macro?
where does malloc() function get the memory?
What is property type c?
while running a program, i got the msg that press return key to exit.what that mean in C as there are no such options as far i know.
What is c method?
how can write all 1to 100 prime numbers using for loop,if and break ?
Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?
Famous puzzles which are generally asked by companies during interviews ?