Arrays and Pointers Quiz

LeadingGingko avatar
LeadingGingko
·
·
Download

Start Quiz

Study Flashcards

18 Questions

Higher-dimensional arrays are commonly used in practice.

False

An array can be passed by value to a function.

False

The following function declarations are exactly equivalent: void func(float array[], int length) and void func(float* array, int length).

True

For fixed 2D arrays, you must specify a fixed number of rows and columns.

True

For malloc'd 2D arrays, you should use a single pointer parameter.

False

Inside a function, the array parameter is a real pointer variable.

True

In C, array elements are numbered starting from 1.

False

An array can store elements of different data types.

False

Strings in C are represented as arrays of characters.

True

A 2D array in C is an array of arrays.

True

Array parameters in C are passed by value.

False

Pointers cannot be used to access array elements.

False

In C programming, you can omit the inner braces when initializing an array.

True

A 2D array in C can be built as an array of pointers to arrays.

True

To construct a 2D array using pointers in C, you need to declare a single pointer.

False

Arrays of malloc'd arrays need to be constructed piece by piece in C.

True

For a 3D array in C, you use three pairs of curly brackets when declaring/accessing it.

False

Using malloc in C can be an alternative way to create higher-dimensional arrays.

True

Study Notes

Arrays

  • An array is a list of variables (“elements”), all having the same type, and a related purpose.
  • Array elements are numbered, starting at zero.
  • Array elements can be accessed by “indexing” the array.

1D Arrays

  • A 1D array cannot be passed by value, only by reference.
  • Two notations for passing 1D arrays to functions are equivalent: void func(float array[], int length) and void func(float* array, int length).
  • Both notations create a pointer, not an array, inside the function.
  • Always pass the array length along with the array itself.

2D Arrays

  • For fixed 2D arrays, use square bracket notation only and specify a fixed number of columns.
  • Optionally, a fixed number of rows can also be specified.
  • For malloc'd 2D arrays, use double pointers only and pass the dimensions as parameters.
  • A 2D array is a single pointer to a 2D array, not a double pointer.

Arrays of Malloc'd Arrays

  • An array of malloc'd arrays is a flexible way to build a 2D array.
  • It is constructed piece by piece using malloc and accessed like a 2D array.

Higher-Dimensional Arrays

  • Higher-dimensional arrays follow the same pattern as 2D arrays.
  • For example, a 3D array can be declared and accessed using three pairs of square brackets.

Test your knowledge on arrays and pointers with this quiz covering topics such as building 2D arrays, arrays of pointers, and array parameters. Explore the concept of arrays of pointers to arrays and their flexibility in terms of knowing dimensions at compile time.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser