Q&A

Q1:Why not make all variables global?
A1: There was a time when this was exactly how programming was done. As programs became more complex, however, it became very difficult to find bugs in programs because data could be corrupted by any of the functions--global data can be changed anywhere in the program. Years of experience have convinced programmers that data should be kept as local as possible, and access to changing that data should be narrowly defined.
Q2:Why aren't changes to the value of function arguments reflected in the calling function?
A2: Arguments passed to a function are passed by value. That means that the argument in the function is actually a copy of the original value.
Q3:What happens if I have the following two functions?
int Area (int width, int length = 1);
int Area (int size);

Will these overload? There are a different number of parameters, but the first one has a default value.

A3: The declarations will compile, but if you invoke Area with one parameter you will receive a compile-time error: ambiguity between Area(int, int) and Area(int).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.196.244