Đây là quyển sách tiếng anh về lĩnh vực công nghệ thông tin cho sinh viên và những ai có đam mê. Quyển sách này trình về lý thuyết ,phương pháp lập trình cho ngôn ngữ C và C++.
[...]... program, taking care of such tasks as transferring command-line arguments (see Chapter 5) to main and main’s return value back to the operating system We are finally ready to treat program memory as the stack that we have been calling it throughout the chapter The name “stack” is purposely descriptive: think of a stack of plates in a cafeteria One can push data (plates) onto the stack and pop data (plates)... and draw the final memory configuration Trade puzzles with a few of your colleagues; check each other’s work 1.1 Playing with Memory 11 1.1.4 How to Crash Your Program There is no faster way to crash a program than to make a mistake with memory (Actually, this statement overstates the case: a program need not crash immediately after an erroneous memory access but can hum merrily and insanely along for. .. values are typically returned to indicate that the program encountered an error or an otherwise exceptional situation during execution 1.2.2 A Protocol for Calling Functions Let’s examine how functions and memory work together The C compiler constructs a stack frame for every function of the program A function’s stack frame is a template of the function’s memory requirements, including space for parameters... programs Rather than taking an abstract and rule-based perspective, this chapter covers the program stack and the function call protocol, which naturally give rise to these concepts A mechanistic understanding of computation lays the foundations for the powerful abstraction methodologies that come later A .R Bradley, Programming for Engineers, DOI 10.1007/978-3-642-23303-6 1, © Springer-Verlag Berlin Heidelberg... memory is fundamental to practical programming, yet many students, through lack of practice, leave their first programming course unable to do so effectively By introducing memory manipulation in the first week, students have a full semester to master the topic Second, the correct usage of call-by-value, call-by-reference, pointers, and arrays is crucial for writing anything but the simplest of programs Rather... we ignore the possible initial values of argc and argv Chapter 5 discusses their usage in depth While modern architectures facilitate more efficient function call and return protocols through the use of on-chip memory (registers), the protocols for calling and returning from a function presented here are representative of those employed by typical compilers and architectures Furthermore, the treatment... the stack In both cases, the operations a ect only the top of the stack Similarly, stack frames are pushed onto and popped off the stack as their corresponding functions are called and return Calling the function sum3 at line 3 causes the following steps to occur, which form the function call protocol: 1 The arguments to sum3 are pushed onto the stack In this case, the three arguments are all 1 because... x, are traditionally called pointers because they “point” to a place in memory Presentations of pointers often draw arrows coming from a pointer variable’s memory cell to the memory cell to which it is pointing For example, in the memory configuration above, one could draw an arrow from the memory cell associated with x to the memory cell associated with a If seeing such arrows would aid your understanding... advanced programming skills and concepts In the first chapter, we introduce memory; in the second, procedure In the third, we combine memory and procedure to study two basic data structures Whereas a traditional programming course reserves “pointers” for late in the semester and may not even mention the stack, let alone how function calling works, this chapter covers both for two reasons First, manipulating... the addresses are the particular values that they are later Each cell is annotated with its associated variable and the type of that variable The type indicates how to interpret the data The symbol ⊗ indicates that a memory cell currently holds garbage—that is, a meaningless value left over from the last time this particular memory was used Since line 2 does not specify initial values for the program