Skip to content

Instantly share code, notes, and snippets.

@Alejandro131
Created January 22, 2014 04:22
Show Gist options
  • Save Alejandro131/8553453 to your computer and use it in GitHub Desktop.
Save Alejandro131/8553453 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void mapInt(int (*func)(int), int a[], int n)
{
for (int i = 0; i < n; i++)
{
a[i] = func(a[i]);
}
}
int doubleInt(int x)
{
return x * 2;
}
int main()
{
int a[5] = {1,2,3,4,5};
mapInt(doubleInt, a, 5);
for (int i = 0; i < 5; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment