Next: Exercises
Up: Introduction to User-defined functions
Previous: Summary
void example(int n) { int i; for (i=0; i<n; i++) cout << '*'; cout << endl; }How would you call this function in a program? How would you use this function in producing the following output on the screen?
* ** *** ****
a)
void change(void) { int x; x = 1; } void main() { int x; x = 0; change(); cout << x << endl; }
b)
void change(int x) { x = 1; } void main() { int x; x = 0; change(x); cout << x << endl; }
float
and returns true (1) if the first parameter
is greater than the second and otherwise returns false (0).
int
and returns true if these two integers are a
valid value for a sum of money in pounds and pence.
If not valid then false should be returned.
ex1
has a local variable named i
and
another function ex2
has a local variable named i
.
These two functions are used together with a main program which has a
variable named i
. Assuming that there are no other errors in
the program will this program compile correctly? Will it execute
correctly without any run-time errors?