Chapter Four
Array, Pointers and Strings
4. Arrays and Strings....................................................................................................... 2
4.1. Introduction ......................................................................................................... 2
4.2. What is an arrays ................................................................................................. 3
4.3. One Dimensional Array ...................................................................................... 3
4.3.1. Declaration of Arrays .................................................................................. 3
4.3.2. Accessing Array Elements .......................................................................... 4
4.3.3. Initialization of arrays ................................................................................. 6
4.3.4. Copying Arrays ........................................................................................... 9
4.4. Multidimensional arrays ................................................................................... 10
4.4.1. Initializing Multidimensional Arrays ........................................................ 11
4.4.2. Omitting the Array Size ............................................................................ 11
4.5. Strings representation and manipulation ........................................................... 12
4.5.1. String Output ............................................................................................. 13
4.5.2. String Input ............................................................................................... 13
4.5.3. Avoiding buffer over flow ........................................................................ 15
4.5.4. String constants ......................................................................................... 15
4.5.5. Copying string the hard way ..................................................................... 15
4.5.6. Copying string the easy way ..................................................................... 16
4.5.7. Concatenating strings ................................................................................ 17
4.5.8. Comparing strings ..................................................................................... 18
4.6. Pointers ............................................................................................................. 19
4.6.1. Dynamic Memory ..................................................................................... 20
4.6.2. Pointer Arithmetic ..................................................................................... 22
4.6.3. Function Pointers ...................................................................................... 23
4.6.4. References ................................................................................................. 25
4.6.5. Typedefs .................................................................................................... 27