Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <iomanip>
- using namespace std;
- int main(int argc, char** argv) {
- void *ptrA, *ptrB;
- int a = 10; // Un tipo de dato
- ptrA = &a;
- int*b = new int;
- *b = 20; // Una variable de tipo puntero a entero
- ptrB = b;
- cout << "Prueba: void* a int* (unico elem.)\n";
- cout << *(int*)ptrA << endl;
- cout << *(int*)ptrB << endl;
- int *c = new int[5];
- for (int i = 0; i < 5; i++) {
- c[i]= i+1;
- }
- void *ptrC;
- ptrC = c;
- cout << *(int*)ptrC << endl; //Apunta solo a la cabecera
- void**ptrRec = (void**)ptrC;
- for (int i = 0; i < 5; i++) {
- cout << i << ") ";
- cout << *((int*)ptrRec+i) << " " << endl; //Aritmetica de ptros
- cout << ((int*)ptrRec)[i] << " " << endl; //Operador de acceso
- int *auxInt = ((int*)ptrRec+i); //Aritmetica de ptros
- int *auxInt = &((int*)ptrRec)[i]; //Operador de acceso
- cout << *auxInt << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement