-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointers.cpp
More file actions
15 lines (8 loc) · 922 Bytes
/
pointers.cpp
File metadata and controls
15 lines (8 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
int main() {
std::cout << "Use the address-of operator '&' before a varible to get hexadecimal location in memory prefix argument name in function declareation with address of operator to accept memory addresses instead so instead of new varibles being created in the function scope it edits and accesses the varibles in the scope you called it from\n";
std::string testString2 = "STRING"; // Make a string
std::string *pTestStrint2 = &testString2; // Create a pointer (they are variables that contain the memory address for another variable), if not setting a pointer immediatly you should make it a null pointer by doing this "std::string *pointer = nullptr;" or "std::string *pointer = NULL;"
std::cout << *pTestStrint2 << '\n'; // Outputs "STRING" not the memory address because we used the dereference oper ator '*' it is common to prefix a pointer with 'p'
return 0;
}