Misconception: When passing arrays in C/C++ students often forget to pass in the size of the array and to use [] (square brackets) to make the variable an array.

Like(421 Likes)
  • When working with arrays, students sometimes forget where to put the number of items they need in an array; this becomes an issue if they want to pass an array as a parameter to a function.
    • In C/C++, arrays are passed with the variable type first and then with the amount of items needed:
      • void printList(string people[], int numOfPeople);
        //In this definition, they often forget to use the brackets to specify that the variable passed is an array, and other times they forget to include an int variable to tell the size of the array.
      • This is a common debugging problem that students have while working with arrays as parameters.
  • Remind students that passing an array in C/C++ requires an array variable (including the []) and the size.

More about this tip

External Source

Interview with Liselot Ramirez