Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-Exam-Practise/Variables/pointers.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (25 sloc)
855 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
/* | |
Pointers. They are the death of me. | |
They are variables that hold memory addresses of other variables. | |
*/ | |
int main() { | |
// normal variable | |
int get_my_address = 10; | |
// outputting normal variable | |
cout << get_my_address << endl; | |
// outputting memory address of the variable | |
cout << &get_my_address << endl; | |
// pointer variable | |
// int *point; | |
// or can be wrote as: | |
// int* point; | |
// define potiner and normal variable (pointer -> point, normal -> p) | |
int* point, p; | |
p = 1010; // assign a value to variable p | |
point = &p; // pointer and add reference to p | |
cout << *point << endl; // return point value NOTE: *point in cout, must be *point or it returns address | |
delete point; // remember to delete to prevent memory leaks | |
return 0; | |
} |