jfcmacro

varmonticulo.cpp

Mar 16th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. /*
  2.  * fichero: varmonticulo.cpp
  3.  *
  4.  * proposito: mostrar la declaracion de variables locales
  5.  *
  6.  * compilar: $ g++ -o varmonticulo varmonticulo.cpp
  7.  *           $ make varmonticulo
  8.  * ejecutar: $ ./varmonticulo
  9.  */
  10. #include <iostream>
  11.  
  12. using namespace std;
  13.  
  14. int
  15. main() {
  16.   // Aputadores a variables de diferentes tipos
  17.   int *pInt = new int;
  18.   bool *pBool = new bool;
  19.   double *pDouble = new double;
  20.  
  21.   // Obtenemos sus direcciones
  22.   cout << "Valores de apuntadores " << endl;
  23.   cout << "pInt: " << pInt << endl;
  24.   cout << "pBool: " << pBool << endl;
  25.   cout << "pDouble: " << pDouble << endl;
  26.  
  27.   // Ahora miramos sus valores
  28.   cout << "Valores de apuntadores " << endl;
  29.   cout << "pInt: " << *pInt << endl;
  30.   cout << "pBool: " << *pBool << endl;
  31.   cout << "pDouble: " << *pDouble << endl;
  32.  
  33.   // Las inicializamos
  34.   *pInt = 10;
  35.   *pBool = false;
  36.   *pDouble = -102.23e12;
  37.  
  38.   // Ahora vemos sus valores
  39.   cout << "Valores de apuntadores " << endl;
  40.   cout << "pInt: " << *pInt << endl;
  41.   cout << "pBool: " << *pBool << endl;
  42.   cout << "pDouble: " << *pDouble << endl;
  43.  
  44.   return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment