24 lines
592 B
C++
24 lines
592 B
C++
|
/*
|
||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/cppFiles/file.cc to edit this template
|
||
|
*/
|
||
|
|
||
|
#include <iostream>
|
||
|
using namespace std;
|
||
|
#include "pointers1.h"
|
||
|
|
||
|
void dereferencePointer() {
|
||
|
int x = 5;
|
||
|
int * p = &x;
|
||
|
int & r = x;
|
||
|
// dereference pointer
|
||
|
cout << *p << " " << p << " " << x << " " << &x << " " << r << " " << &r << endl;
|
||
|
}
|
||
|
|
||
|
int * createAnIntegerOnHeap(int x) {
|
||
|
int * p = new int;
|
||
|
if (p == nullptr) {
|
||
|
return nullptr;
|
||
|
}
|
||
|
return p;
|
||
|
}
|