Professional Documents
Culture Documents
int i, j, k;
float f, balance;
double d;
listing 2
#include <iostream>
using namespace std;
void func();
int main()
{
int x; // local to main()
x = 10;
func();
cout << "\n";
cout << x; // displays 10
return 0;
}
void func()
{
int x; // local to func()
x = -199;
cout << x; // displays -199
}
listing 3
int func1(int first, int last, char ch)
{
.
.
.
}
listing 4
#include <iostream>
using namespace std;
void func1();
void func2();
int main()
{
int i; // this is a local variable
return 0;
}
void func1()
{
cout << "count: " << count; // access global count
cout << '\n'; // output a newline
func2();
}
void func2()
{
int count; // this is a local variable
listing 5
#include <iostream>
using namespace std;
j = 60000;
i = j;
cout << i << " " << j;
return 0;
}
listing 6
unsigned x;
unsigned int y;
listing 7
// This program prints the alphabet in reverse order.
#include <iostream>
using namespace std;
int main()
{
char letter;
return 0;
}
listing 8
ch = 'Z';
listing 9
wchar_t wc;
wc = L'A';
listing 10
hex = 0xFF; // 255 in decimal
oct = 011; // 9 in decimal
listing 11
#include <iostream>
using namespace std;
int main()
{
cout << "\n\\\b";
return 0;
}
listing 12
char ch = 'a';
int first = 0;
float balance = 123.23F;
listing 13
// An example that uses variable initialization.
#include <iostream>
using namespace std;
int main()
{
cout << "Computing summation of 5.\n";
total(5);
return 0;
}
void total(int x)
{
int sum=0; // initialize sum
int i, count;
listing 14
#include <iostream>
using namespace std;
int main()
{
int x, y;
x = 10;
y = 3;
cout << x/y; // will display 3
cout << "\n";
cout << x%y; /* will display 1, the remainder of
the integer division */
cout << "\n";
x = 1;
y = 2;
cout << x/y << " " << x%y; // will display 0 1
return 0;
}
listing 15
x = x+1;
listing 16
++x;
listing 17
x = x-1;
listing 18
--x;
listing 19
x = x+1;
listing 20
++x; // prefix form
listing 21
x++; // postfix form
listing 22
x = 10;
y = ++x;
listing 23
x = 10;
y = x++;
listing 24
bool xor(bool a, bool b)
{
return (a || b) && !(a && b);
}
listing 25
// This program demonstrates the xor() function.
#include <iostream>
using namespace std;
int main()
{
bool p, q;
return 0;
}
listing 26
var>15 || !(10<count) && 3<=item
listing 28
(float) x / 2
listing 29
#include <iostream>
using namespace std;
return 0;
}
listing 30
x=10/y*(127/x);
x = 10 / y * (127/x);
listing 31
x = y/3-34*temp+127;