C Programming Week11
C Programming Week11
Multi-dimensional Arrays
• char multi[4][10];
– multi[4] – an array of ten characters
– 4 such arrays
CS1100 multi[0] = {‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’}
Introduction to Programming multi[1] = {‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’}
multi[2] = {‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’}
Multi-Dimensional Arrays multi[3] = {‘9’, ‘8’, ‘7’, ‘6’, ‘5’, ‘4’, ‘3’, ‘2’, ‘1’, ‘0’}
• Individual elements are addressable:
Madhu Mutyam
Department of Computer Science and Engineering – multi[0][3] = ‘3’
Indian Institute of Technology Madras
1
30/10/17
• Answer:
– It is de-referenced
Address(multi+1) = address(multi) + 10
– Remember a 2-D array is a pointer to a pointer Because the character array has 10 columns
– *(array + row) de-references to a pointer to a 1-D array Each of these is a pointer to a pointer (or pointer to a 1-D array)
– *(array + row) + 1 would do a pointer increment
SD, PSK, NSN, DK, TAG – CS&E, IIT M 9 SD, PSK, NSN, DK, TAG – CS&E, IIT M 10
SD, PSK, NSN, DK, TAG – CS&E, IIT M 11 SD, PSK, NSN, DK, TAG – CS&E, IIT M 12
2
30/10/17
SD, PSK, NSN, DK, TAG – CS&E, IIT M 17 SD, PSK, NSN, DK, TAG – CS&E, IIT M 18
3
30/10/17