placeholder image to represent content

C++ Programming- Arrays

Quiz by Sandhya

Our brand new solo games combine with your quiz, on the same screen

Correct quiz answers unlock more play!

New Quizalize solo game modes
10 questions
Show answers
  • Q1
    In C++, how do you declare an array named 'numbers' with 5 elements of type int?
    array numbers[5];
    numbers = int[5];
    int numbers[5];
    int[] numbers = new int[5];
    30s
  • Q2
    How do you access the fourth element in an array named 'scores' in C++?
    scores{4};
    scores[3];
    scores$4;
    scores(3);
    30s
  • Q3
    What is the syntax to assign the value 10 to the third element in an array named 'data' in C++?
    data[2] = 10;
    assign data[2] = 10;
    10 = data[2];
    data{2} = 10;
    30s
  • Q4
    How do you iterate through all elements of an array named 'ages' and print each element in C++?
    for(int i = 0; i < sizeof(ages) / sizeof(ages[0]); i++) { cout << ages[i] << ' '; }
    while(int i = 0; i < ages.length; i++) { cout << ages[i] << ' '; }
    for(int i = 1; i < sizeof(ages); i++) { cout << ages[i] << ' '; }
    foreach(int i in ages) { cout << i << ' '; }
    30s
  • Q5
    What is the correct way to declare a 2D array named 'matrix' with 3 rows and 4 columns in C++?
    int matrix = new int[3][4];
    int matrix(3, 4);
    int matrix[3][4];
    matrix = int[3][4];
    30s
  • Q6
    What is the syntax to access the value at row 1, column 2 in a 2D array named 'grid' in C++?
    grid{1, 2};
    grid(1, 2);
    grid$1$2;
    grid[1][2];
    30s
  • Q7
    What is the output of the following code snippet in C++? int numbers[] = {10, 20, 30, 40, 50}; cout << numbers[2];
    50
    40
    10
    30
    30s
  • Q8
    How do you find the number of elements in an array named 'myArray' in C++?
    length(myArray)
    sizeOfArray(myArray)
    countElements(myArray)
    sizeof(myArray) / sizeof(myArray[0])
    30s
  • Q9
    What is an array in C++?
    A function that calculates the sum of elements in a sequence.
    A type of loop used for iteration in C++.
    A standard input/output operation in C++.
    A collection of elements of the same data type stored in contiguous memory locations.
    30s
  • Q10
    How do you use a loop to initialize an array named 'scores' with values 1 to 10 in C++?
    while(scores <= 10) { scores[scores] = i; i++; }
    for(int i = 0; i < 10; i++) { scores[i] = i + 1; }
    for(int i = 1; i <= 10; i++) { scores[i-1] = i; }
    for(int i = 1; i < 11; i++) { scores[i] = i; }
    30s

Teachers give this quiz to your class