Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- //We have to make a copy of number because number is can only be in the local scope and myNumber in main scope.
- void test(int number) //number = 1 //It's taking the value of myNumber and setting it to the variable number.
- {
- cout << number << endl;
- number++;
- cout << number << endl;
- }
- int main()
- {
- int myNumber = 1;
- test(myNumber); //myNumber = number // number is now a copy of myNumber
- cout << myNumber << endl;
- }
- //You're essentially creating a copy for number in the test() scope. Then using the copy in main().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement