cin >> beta;
alpha -= beta;
the variable beta
is local to the block that is the body of the while
statement.
int main( )
{
void SomeFunction( )
{
the variable gamma
is global to all functions in the example.
#include <iostream.h>
// ----------------------
Prototypes
void Fun(int, char&);
// -------------------------
globals
int a;
int b;
// ----------------------------
main
int main()
{
// -----------------------------
Fun
void Fun(int b, char &c)
{
while
(. . .)
{
int a;
}
}


For static variables, which are allocated only once, the
initialization occurs only once - the first time the variable is allocated.
sum += value;
count++;
avg = double(sum) / double(count);
return avg;
What would happen if sum and count were not static variables?
Why is avg not a static variable?
int count;
// Line counter
char ch;
// Holds one input char
// ------------------------------
main
int main()
{
cout << count <<
" lines processed"
<< endl;
// ------------------------
CountChars
void CountChars()
{
cout << count
<< " characters on this line"
<< endl;
The above example should print the
number of characters in each line as they are read. Then after the last
line of input, it should print the number of lines processed. Instead,
it always prints the number of lines processed as the same number as the
number of characters in the last line. Why?

if (y < small)
return small;
|
|
|
|
| isalpha(ch) |
|
Nonzero, if ch is a letter ('A'-'Z', 'a'-'z');
0 otherwise |
| isalnum(ch) |
|
Nonzero, if ch is a letter or digit ('A'-'Z',
'a'-'z','0'-'9');
0 otherwise |
| isdigit(ch) |
|
Nonzero, if ch is a numeral ('0'-'9');
0 otherwise |
| islower(ch) |
|
Nonzero, if ch is a lowercase letter ('a'-'z');
0 otherwise |
| isupper(ch) |
|
Nonzero, if ch is a uppercase letter ('A'-'Z');
0 otherwise |
| isspace(ch) |
|
Nonzero, if ch is a whitespace character (blank,
newline, tab, caraiage return, form feed);
0 otherwise |
Copyright 1998 by Thomas C. Irby.