18 lines
382 B
C++
18 lines
382 B
C++
#include <iostream>
|
|
#include <cassert>
|
|
using namespace std;
|
|
|
|
int f(int x) { return ++x;}
|
|
int g(int& x) { return ++x;}
|
|
int main() {
|
|
int x = 2;
|
|
/* f is "functional", as it has no side-effects */
|
|
f(x);
|
|
assert(x==2);
|
|
/* g changes a variable of an outer scope,
|
|
* i.e. it has a side effect
|
|
* Thus, g is not functional!
|
|
*/
|
|
g(x);
|
|
assert(x!=2);
|
|
}
|