Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdlib.h>
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- using namespace std;
- int f(int& a, int& b, int x, int y); // по значению
- int ff(int& a, int& b, int &x, int &y) // со ссылке
- {
- if(y == 0)
- {
- return 0;
- }
- a = x*y;
- b = x/y;
- return 1;
- }
- int f(int& a, int& b, int *x, int *y) // со указателю
- {
- if((*y) == 0)
- {
- return 0;
- }
- a = (*x)*(*y);
- b = (*x)/(*y);
- return 1;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int a = 10;
- int b = 5;
- cout << "Начальные a = " << a << ", b = " << b << endl;
- cout << "передача x, y по значению - return: " << f(a, b, 21, 7) << endl;
- cout << "a = " << a << endl;
- cout << "b = " << b << endl;
- int x = 24;
- int y = 4;
- cout << "передача x, y по ссылке - return: " << ff(a, b, x, y) << endl;
- cout << "a = " << a << endl;
- cout << "b = " << b << endl;
- x = 16;
- y = 0;
- cout << "передача x, y по указателю - return: " << f(a, b, &x, &y) << endl;
- cout << "a = " << a << endl;
- cout << "b = " << b << endl;
- getch();
- return 0;
- }
- int f(int& a, int& b, int x, int y)
- {
- if(y == 0)
- {
- return 0;
- }
- a = x*y;
- b = x/y;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement