Monday, September 8, 2008

Apple ACPT Certification Exam 9L0-402

The first variable 'i' is put out of scope in two separate sections. Thus the repeated 9L0-509 statement cout << i << ' '; means something very different each time it is written. The 'i' referred to is a different location in memory on each occasion. This is what was meant by `context' in the introduction: the context or background in which the statement is placed of is different each time, so the statement does something different in each place.
It is always Pass4sure 9L0-402 an error to declare the same variable name twice within the same level of scope.
There are important things to note about the above example. That program is only an example program and unusually convoluted; it is useful to demonstrate the idea of scope and little else. So while it illustrates the concept of scope, it fails to illustrate 9L0-509 usefully the purpose of scope.

Some variables are required to store information for an entire program, while other variables are short-term variables which are brought into existence momentarily for a single small purpose and then disposed of, by going out of scope. In the following program, an array of numbers is read in and then a procedure is called that computes the average of the 9L0-402 Exam numbers in the array. Within the procedure, in order to move through the array and select the elements in the array in turn, a variable 'i' is created for that one purpose. Contrast the two kinds of variable: the array itself, which is in scope throughout the entire program, and the variable 'i' which is in scope only for a small section of the code, to do its own little job.

No comments: