1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <iostream>
using namespace std;
void unefonction( void* pletableau, int nboctets, unsigned char valeur);
int main()
{
int myarray[10] =
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
};
int* p = myarray;
void* pv = static_cast<void*>(p);
for (unsigned int i = 0; i <= (sizeof(myarray) / sizeof(*myarray))-1; i++)
{
cout << "myarray[" << i << "] = " << myarray[i] << endl;
}
cout << endl;
unefonction( pv, ((sizeof(myarray) / sizeof(*myarray))*sizeof(int)), 4);
cout << endl;
for (unsigned int i = 0; i <= (sizeof(myarray) / sizeof(*myarray))-1; i++)
{
cout << "myarray[" << i << "] = " << myarray[i] << endl;
}
}
void unefonction( void* pletableau, int nboctets, unsigned char valeur)
{
unsigned char*tableauDuBonType = static_cast<unsigned char*>(pletableau);
for (int i = 0 ; i < nboctets ; ++i)
{
tableauDuBonType[i] = valeur;
}
} |
Partager