### help me with void pointers

Can you explain me this code line by line with detailed explanation?
and when should i start learning win api? im have covered the tutorial in this site to pointers. i have little understanding in classes, thats all. when should i learn win api??
here is the code:
//explain me line by line
// pointer to functions
#include <iostream>
using namespace std;

int addition (int a, int b)
{ return (a+b); }

int subtraction (int a, int b)
{ return (a-b); }

int operation (int x, int y, int (*functocall)(int,int))
{
int g;
g = (*functocall)(x,y);
return (g);
}

int main ()
{
int m,n;
int (*minus)(int,int) = subtraction;

m = operation (7, 5, addition);
n = operation (20, m, minus);
cout <<n;
return 0;
}
Thanks.
Mr. Puff
What are you struggling with exactly?

There are no void pointers here. There are function pointers but they're different.
a simple search of this site would have produced this:

http://www.cplusplus.com/forum/beginner/105731/
i dont understand please explain me everything pls
HELP
 1234567891011121314151617181920212223242526 #include using namespace std; int addition (int a, int b) { return (a+b); } int subtraction (int a, int b) { return (a-b); } int operation (int x, int y, int (*functocall)(int,int)) { int g; g = (*functocall)(x,y); return (g); } int main () { int m,n; int (*minus)(int,int) = subtraction; m = operation (7, 5, addition); n = operation (20, m, minus); cout <

main()
19: declare two variables of type int
20: declare one variable of type pointer to a function that looks like int func(int, int). Initialise it with address of function subtraction.
22: call function operation, pass parameters 7, 5, address of function addition
23: call function operation, pass parameters 20, m, minus (which is the address of subtraction)

operation()
10: operation is a function that takes 3 parameters, x of type int, y of type int, functocall of type pointer to a function that looks like int func(int, int)
12: declare variable g of type int
13: call the function who's address in in local variable functocall, with parameters x, y and save the result in g
This really should be:
 g = functocall(x,y);

14: return g
Last edited on
Explaining that code line-by-line is a waste of time.

For example, I'm assuming you know what's happening in this line:
int m,n;

Why don't you specify exactly what you're stuck on. That way, you'll get a better suited answer. Is it the function pointer syntax? The function pointer itself?
line 10 -15
and how you pass paramets to that function and that function and what is null pointers what is so good using null pointers? what is (*minus)?
i know what is v(void *) its casting no?

explain this code too!! what parameters passed to functions??
#include<iostream.h>

void swap(int &a,int &b);

int main()
{
int num1=5,num2=10;
swap(num1,num2);
cout << num1 << endl << num2;
return 0;
}

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
Last edited on
 line 10 -15 and how you pass paramets to that function
 g = functocall(x,y);

 what is null pointers what is so good using null pointers?
A pointer is a variable that holds a memory location. So it can point to some value or not. It's conventional to assign it the value NULL to indicate that the pointer isn't pointing at anything.

 what is (*minus)?