// ------------------
// LocalVariables.c++
// ------------------
#include <cassert> // assert
#include <iostream> // cout, endl
int f () {
int v = 2;
++v;
return v;}
int g () {
// const int cv; // error: uninitialized const "cv"
const int cv = 2;
// ++cv; // error: increment of read-only variable "cv"
return cv;}
int h () {
static int sv = 2;
++sv;
return sv;}
int q () {
// static const int scv; // error: uninitialized const "scv"
static const int scv = 2;
// ++scv; // error: increment of read-only variable "scv"
return scv;}
int main () {
using namespace std;
cout << "LocalVariables.c++" << endl;
{
const int u = f();
assert(u == 3);
const int w = f();
assert(w == 3);
}
{
const int u = g();
assert(u == 2);
const int w = g();
assert(w == 2);
}
{
const int u = h();
assert(u == 3);
const int w = h();
assert(w == 4);
}
{
const int u = q();
assert(u == 2);
const int w = q();
assert(w == 2);
}
cout << "Done." << endl;
return 0;}
syntax highlighted by Code2HTML, v. 0.9.1