The author of the worm was caught and prosecuted he

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } int test() { int x = 2; fun(&x); return x; } Figure 3.25: Code Illustrating Use of Pointers in C. In C, pointers can be generated to any data type. 164 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS ¯ ¯ Arrays and pointers are closely related. The name of an array can be referenced (but not updated) as if it were a pointer variable. Array referencing (e.g., a[3]) has the exact same effect as pointer arithmetic and dereferencing (e.g., *(a+3)). We can see this in line 29, where we print the pointer value of array ip, and reference its first (element 0) entry as *ip. Pointers can also point to functions. This provides a powerful capability for storing and passing references to code, which can be invoked in some other part of the program. We see this with variable f (line 15), which is declared to be a variable that points to a function taking an int * as argument and returning void. The assignment makes f point to fun. When we later apply f (line 36), we are making a recursive call. New to C? The syntax for declaring function pointers is especia...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online