Guest User

Untitled

a guest
Jan 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. int main()
  2. {
  3. int *p; int tam;
  4. cout << "Ingrese el tamaño" << endl;
  5. cin >> tam;
  6. p = new int[tam + 5];
  7. p[0] = 67;
  8. p[1] = 72;
  9. p[2] = 15;
  10. p[3] = 81;
  11. p[4] = 23;
  12. cout << *(p+2) << endl;
  13. return 0;
  14. }
  15.  
  16. int main()
  17. {
  18. int *p; int tam;
  19. cout << "Ingrese el tamaño" << endl;
  20. /* Guardamos el entero que introduzcan en la variable "tam" */
  21. cin >> tam;
  22. /* Creamos una matriz unidimensional (vector) de (tam + 5) elementos */
  23. p = new int[tam + 5];
  24. /* Ninguno genera error a menos que "tam" sea negativo, en cuyo caso
  25. podríamos provocar un volcado de pila por violación de segmento */
  26. p[0] = 67;
  27. p[1] = 72;
  28. p[2] = 15;
  29. p[3] = 81;
  30. p[4] = 23;
  31. /* "p" apunta al elemento 0, por lo que p + 2 incrementa el puntero
  32. 2 posiciones de tamaño "int", accediendo al elemento 0 + 2 = 2 (15) */
  33. cout << *(p+2) << endl;
  34. return 0;
  35. }
  36.  
  37. int* ptr = new int;
  38. MiClase* obj = new MiClase(param1,param2);
  39.  
  40. int* ptr = new int[5]; // array de 5 elementos de tipo int
  41. MiClase** lista = new MiClase*[10]; // array de 10 elementos de tipo MiClase*
  42.  
  43. p + 0 = 67;
  44. p + 1 = 72;
  45. p + 2 = 15;
  46. p + 3 = 81;
  47. p + 4 = 23;
Add Comment
Please, Sign In to add comment