Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created January 17, 2023 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/c696b530e43ee4767331e9586d59bc54 to your computer and use it in GitHub Desktop.
Save JoshCheek/c696b530e43ee4767331e9586d59bc54 to your computer and use it in GitHub Desktop.
c++ value/pointer/reference example
#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