Created
January 17, 2023 03:29
-
-
Save JoshCheek/c696b530e43ee4767331e9586d59bc54 to your computer and use it in GitHub Desktop.
c++ value/pointer/reference example
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; | |
void print_by_value(string message) { cout << message << endl; } | |
void print_by_pointer(string *message) { cout << *message << endl; } | |
void print_by_reference(string &message) { cout << message << endl; } | |
int main() { | |
string message = "whatever"; | |
print_by_value(message); | |
print_by_pointer(&message); | |
print_by_reference(message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment