Những dòng mã khai báo một biến x tồn tại, rằng nó là kiểu int, và một y biến kiểu int cũng tồn tại. (Phần tiếp theo thảo luận về các loại vari có thể) Bạn có thể khai báo các biến (gần như) bất cứ nơi nào bạn muốn trong chương trình của bạn - miễn là bạn khai báo các biến trước khi bạn sử dụng nó. | 116 Part II Becoming a Functional C Programmer LayoutError - demonstrate the results of a messing up a pointer usage include cstdio include cstdlib include iostream using namespace std int main int nNumberofArgs char pszArgs int upper 0 i nt n 0 int lower 0 output the values of the three variables before. cout the initial values are endl cout upper upper endl cout n n endl cout lower lower endl now store a double into the space allocated for an int cout nStoring into the location n endl double pD double n pD display the results cout nThe final results are endl cout upper upper endl cout n n endl cout lower lower endl wait until user is ready before terminating program to allow the user to see the program results system PAUSE return 0 The first three lines in main declare three integers in the normal fashion. The assumption made here is that these three variables are laid out next to each other. The next three executable lines output the value of the three variables. Not surprisingly all three variables display as 0. The assignment pD stores the double value in the integer variable n. The three output statements display the values of all three variables after the assignment. After assigning the double value in the integer variable n n is not modified at all however the nearby variable upper is filled with a garbage value. This is not good as the output from the program shows the initial values are upper 0 Chapter 8 Taking a First Look at C Pointers 117 n 0 lower 0 Storing into the location n The final results are upper 1076494336 n 0 lower 0 Press any key to continue . . . The house equivalent goes something like this House houseAddress 123 Main Street Hotel hotelAddress hotelAddress Hotel houseAddress hotelAddress TheRitz houseAddress is initialized to point to my house. The variable hotelAddress is a pointer to a hotel. Now the house address is cast into the address of a hotel and saved off into the variable hotelAddress. Finally .