Pointers and Modular Programming: Mirza Mohammad Lutfe Elahi
Pointers and Modular Programming: Mirza Mohammad Lutfe Elahi
Programming
Outline
• Pointer Variables
• Address Operator and Indirect Reference
• Functions with Output Parameters
• Multiple Calls to a Function
• Scope of Names
• File Input and Output
• Common Programming Errors
Address Operator
• How to initialize a pointer variable?
• We can use the address operator &
• Example:
int m = 25;
int *itemp; /* pointer variable */
itemp = &m; /* Store address of m in pointer
itemp */
p=2293320 d = 13.5
Summary
• Using a pointer variable p, one can access:
1. Its direct value: the value of pointer variable p
– In the example, the value of p is 2293320
– It is the address of variable d (&d is 2293320)
Sort 3 Numbers
Scope of a Name
• Region of program where a name is visible
• Region of program where a name can be referenced
• Scope of: #define NAME value
– From the definition line until the end of file
– Visible to all functions that appear after #define
• Scope of a function prototype
– Visible to all functions defined after the prototype
• Scope of a parameter and a local variable
– Visible only inside the function where it is defined
– Same name can be re-declared in different functions
CSE 115 Programming Language I ECE@NSU
18
MAX and LIMIT are visible to all functions
Sample Run
• File: indata.txt
344 55 6.3556 9.4
43.123 47.596
• File: outdata.txt
344.00
55.00
6.36
9.40
43.12
47.60