MCS-208 · Unit 2

Arrays, Pointers and Structures

8 sections

Block 1 · Unit 2Arrays, Pointers and Structures79 min · 8 sections

Unit 2Arrays, Pointers and Structures

Follows IGNOU MCS-208, Unit 2

The array is the simplest and most widely used data structure: a fixed number of values of one type, stored side by side in memory. This unit shows how arrays work in C, how they are tied to pointers, and how they are laid out in memory. It then uses arrays (and structures, which group values of different types) to store two classic kinds of data compactly: sparse matrices and polynomials. Almost every later data structure, from stacks to hash tables, is built on top of an array.

In this unit you will learn to

  • declare, initialise and size one-dimensional and multidimensional arrays in C;
  • work with strings as arrays of characters ending in '\0';
  • explain how array names, pointers and subscripts are related;
  • store a sparse matrix in 3-tuple form and write the program that builds it;
  • define and use structures, arrays of structures and pointers to structures;
  • represent polynomials with arrays and add two polynomials efficiently;
  • calculate the address of any element in row-major and column-major order;
  • decide when an array is (and is not) the right data structure.

Sections in this unit

  1. 2.1One-Dimensional ArraysWhat an array is, how to declare and initialise it in C, how much memory it needs, and its lower bound, upper bound and size.9 min
  2. 2.2Strings and Multidimensional ArraysStrings as character arrays ending in '\0', the difference between '\0' and '0', and declaring and sizing 2-D and n-D arrays.8 min
  3. 2.3Arrays and PointersHow an array name converts to a pointer, why a[i] equals *(a + i), pointer arithmetic, and the address formula for 2-D arrays.12 min
  4. 2.4Sparse Matrices and the 3-Tuple FormTriangular, tridiagonal and sparse matrices, the 3-tuple representation, how much memory it saves, and a correct C program to build it.9 min
  5. 2.5StructuresStructures in C: declaring them, accessing members with . and ->, arrays of structures, typedef, and why sizeof can exceed the sum of members.10 min
  6. 2.6PolynomialsRepresenting a polynomial with arrays or structures, and adding two polynomials in O(m + n) time with a merge-style algorithm.10 min
  7. 2.7Row-Major and Column-Major RepresentationHow a 2-D array is laid out in memory row by row or column by column, and how to calculate the address of any element in both orders.14 min
  8. 2.8Applications of Arrays: Strengths and LimitsWhen arrays are the right choice, the cost of access, search, insertion and deletion, and where arrays are used in practice.7 min
↑ ↓ move↵ openTab switch type