Could Pass-by-Reference be implemented without pointers?
This might be more a question on computer architecture than on C++ itself, but I was wondering if pass-by-reference could theoretically be implemented without using pointers in a language like C++. Here are three examples of code that have similar function and structure. //Version 1: Uses global variable #include <iostream> int global_var = 0; int increment(void) {return ++global_var;} int main(void) { while (global_var < 100) printf("Counter: %i\n", increment()); return 0; } //Version 2: Uses pass-by-pointer #include <iostream> int increment(int* ptr) {return ++(*ptr);} int main(void) { int l
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.