Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this simple program shows use of the address operator,
- //cin as a condition,
- //and cin.get() to pause a program indefinitely
- #include <iostream>
- using namespace std;
- void sx(int&);
- void output(int&);
- void pauseProgram();
- int main()
- {
- int x;
- sx(x);
- output(x);
- pauseProgram();
- return 0;
- }
- void sx(int &x) //this function demonstrates using cin as a condition. since it takes x as a reference parameter it doesn't need to return x.
- {
- while(!(cin>>x))
- {
- cin >> x;
- cin.clear();
- cin.ignore(100,'\n');
- }
- return;
- }
- void output(int &x) //this function is a simple cout function to simplify main
- {
- cout << endl;
- cout << "The value of x is: " << x << endl;
- cout << "The memory address of x is: " << &x << endl;
- return;
- }
- void pauseProgram() //this simple function pauses the program until any key even enter/return is pressed.
- {
- cin.get();
- cin.get();
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment