jfcmacro icon

varmonticulo.cpp

jfcmacro | PRO | 03/16/19 07:47:45 PM UTC | 0 ⭐ | 414 👁️ | Never ⏰ | []
C++ |

1.05 KB

|

None

|

0 👍

/

0 👎

/*
 * fichero: varmonticulo.cpp
 *
 * proposito: mostrar la declaracion de variables locales
 *
 * compilar: $ g++ -o varmonticulo varmonticulo.cpp
 *           $ make varmonticulo
 * ejecutar: $ ./varmonticulo
 */
#include <iostream>
 
using namespace std;
 
int
main() {
  // Aputadores a variables de diferentes tipos
  int *pInt = new int;
  bool *pBool = new bool;
  double *pDouble = new double;
 
  // Obtenemos sus direcciones
  cout << "Valores de apuntadores " << endl;
  cout << "pInt: " << pInt << endl;
  cout << "pBool: " << pBool << endl;
  cout << "pDouble: " << pDouble << endl;
 
  // Ahora miramos sus valores
  cout << "Valores de apuntadores " << endl;
  cout << "pInt: " << *pInt << endl;
  cout << "pBool: " << *pBool << endl;
  cout << "pDouble: " << *pDouble << endl;
 
  // Las inicializamos
  *pInt = 10;
  *pBool = false;
  *pDouble = -102.23e12;
 
  // Ahora vemos sus valores
  cout << "Valores de apuntadores " << endl;
  cout << "pInt: " << *pInt << endl;
  cout << "pBool: " << *pBool << endl;
  cout << "pDouble: " << *pDouble << endl;
 
  return 0;
}

Comments