Pointers On C
Instructor’s Guide
www.linuxidc.com
www.linuxidc.com
www.linuxidc.com
www.linuxidc.com
Pointers on C—Instructor´s Guide i
Contents
Chapter 1 A Quick Start ........................................................................................................ 1
Chapter 2 Basic Concepts ...................................................................................................... 7
Chapter 3 Data ....................................................................................................................... 11
Chapter 4 Statements ............................................................................................................. 15
Chapter 5 Operators and Expressions .................................................................................... 23
Chapter 6 Pointers .................................................................................................................. 29
Chapter 7 Functions ............................................................................................................... 37
Chapter 8 Arrays .................................................................................................................... 43
Chapter 9 Strings, Characters, and Bytes .............................................................................. 55
Chapter 10 Structures and Unions ........................................................................................... 69
Chapter 11 Dynamic Memory Allocation ................................................................................ 75
Chapter 12 Using Structures and Pointers ............................................................................... 79
Chapter 13 Advanced Pointer Topics ...................................................................................... 87
Chapter 14 The Preprocessor ................................................................................................... 93
Chapter 15 Input/Output Functions .......................................................................................... 95
Chapter 16 Standard Library .................................................................................................... 119
Chapter 17 Classic Abstract Data Types ................................................................................. 129
Chapter 18 Runtime Environment ........................................................................................... 145
www.linuxidc.com
www.linuxidc.com
www.linuxidc.com
www.linuxidc.com
1
A Quick Start
1.1 Questions
1. To make the program easier to read, which in turn makes it easier to maintain later.
3. It is easier to see what a named constant represents, if it is well named, than a literal constant,
which merely displays its value.
4.
"%d %s %g\n"
6. The programmer can put in subscript checks where they are needed; in places where the sub-
script is already known to be correct (for example, from having been checked earlier), there is no
overhead expended in checking it again. But the real reason they are omitted is the fact that sub-
scripts are implemented as pointer expressions, which are described in Chapter 8.
7. More characters would be copied than are actually needed; however, the
output_col would be
updated properly, so the next range of characters would be copied into the output array at the
proper place, replacing any extra characters from the preceding operation. The only potential
problem is that the unbounded
strcpy might copy more characters into the output array than it
has room to hold, destroying some other variables.
1.2 Programming Exercises
1. Watch the solutions for proper use of void declarations and a reasonable style. The first pro-
gram is no place to begin learning bad habits. The program will compile and run on most sys-
tems without the
#include statement.
/*
** Print the message "Hello world!" to the standard output.
*/
#include <stdio.h>
void
main( void )
Solution 1.1
continued . . .
1
www.linuxidc.com
www.linuxidc.com