Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- int *p; int tam;
- cout << "Ingrese el tamaño" << endl;
- cin >> tam;
- p = new int[tam + 5];
- p[0] = 67;
- p[1] = 72;
- p[2] = 15;
- p[3] = 81;
- p[4] = 23;
- cout << *(p+2) << endl;
- return 0;
- }
- int main()
- {
- int *p; int tam;
- cout << "Ingrese el tamaño" << endl;
- /* Guardamos el entero que introduzcan en la variable "tam" */
- cin >> tam;
- /* Creamos una matriz unidimensional (vector) de (tam + 5) elementos */
- p = new int[tam + 5];
- /* Ninguno genera error a menos que "tam" sea negativo, en cuyo caso
- podríamos provocar un volcado de pila por violación de segmento */
- p[0] = 67;
- p[1] = 72;
- p[2] = 15;
- p[3] = 81;
- p[4] = 23;
- /* "p" apunta al elemento 0, por lo que p + 2 incrementa el puntero
- 2 posiciones de tamaño "int", accediendo al elemento 0 + 2 = 2 (15) */
- cout << *(p+2) << endl;
- return 0;
- }
- int* ptr = new int;
- MiClase* obj = new MiClase(param1,param2);
- int* ptr = new int[5]; // array de 5 elementos de tipo int
- MiClase** lista = new MiClase*[10]; // array de 10 elementos de tipo MiClase*
- p + 0 = 67;
- p + 1 = 72;
- p + 2 = 15;
- p + 3 = 81;
- p + 4 = 23;
Add Comment
Please, Sign In to add comment