EmSAT Achieve Exam  >  EmSAT Achieve Tests  >  Test: Arrays - 1 - EmSAT Achieve MCQ

Test: Arrays - 1 - EmSAT Achieve MCQ


Test Description

20 Questions MCQ Test - Test: Arrays - 1

Test: Arrays - 1 for EmSAT Achieve 2024 is part of EmSAT Achieve preparation. The Test: Arrays - 1 questions and answers have been prepared according to the EmSAT Achieve exam syllabus.The Test: Arrays - 1 MCQs are made for EmSAT Achieve 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Arrays - 1 below.
Solutions of Test: Arrays - 1 questions in English are available as part of our course for EmSAT Achieve & Test: Arrays - 1 solutions in Hindi for EmSAT Achieve course. Download more important topics, notes, lectures and mock test series for EmSAT Achieve Exam by signing up for free. Attempt Test: Arrays - 1 | 20 questions in 40 minutes | Mock test for EmSAT Achieve preparation | Free important questions MCQ to study for EmSAT Achieve Exam | Download free PDF with solutions
Test: Arrays - 1 - Question 1

How are arrays stored in memory in C++?

Detailed Solution for Test: Arrays - 1 - Question 1

Arrays in C++ are stored in contiguous memory locations, meaning that the elements of an array are stored one after another in memory.

Test: Arrays - 1 - Question 2

What is the index of the first element in an array with N elements?

Detailed Solution for Test: Arrays - 1 - Question 2

In C++, the index of the first element in an array is 0.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Arrays - 1 - Question 3

Which of the following statements is true about passing arrays to functions in C++?

Detailed Solution for Test: Arrays - 1 - Question 3

In C++, arrays are automatically passed by reference to functions. When an array is passed to a function, any modifications made to the array within the function will affect the original array.

Test: Arrays - 1 - Question 4

Which of the following is the correct syntax to declare a 1D array of integers in C++?

Detailed Solution for Test: Arrays - 1 - Question 4

The correct syntax to declare a 1D array of integers in C++ is "int array[]". The size of the array can be specified or left empty.

Test: Arrays - 1 - Question 5

What is the time complexity of searching an element in an array using binary search (iterative method)?

Detailed Solution for Test: Arrays - 1 - Question 5

Binary search has a time complexity of O(log N) when applied to a sorted array. It repeatedly divides the search space in half, reducing the search range by half with each comparison.

Test: Arrays - 1 - Question 6

Which of the following is the correct formula to calculate the middle index in binary search?

Detailed Solution for Test: Arrays - 1 - Question 6

The correct formula to calculate the middle index in binary search is "middle = (start + end) / 2". This formula finds the midpoint between the start and end indices.

Test: Arrays - 1 - Question 7

Binary search can be applied on which of the following types of arrays?

Detailed Solution for Test: Arrays - 1 - Question 7

Binary search can be applied only to sorted arrays. It relies on the property of the array being sorted to efficiently locate the desired element.

Test: Arrays - 1 - Question 8

What is an array in C++?

Detailed Solution for Test: Arrays - 1 - Question 8

An array is a collection of variables of the same data type, identified by a common name.

Test: Arrays - 1 - Question 9

How are arrays stored in memory?

Detailed Solution for Test: Arrays - 1 - Question 9

Arrays in C++ are stored in a sequential manner in contiguous memory locations.

Test: Arrays - 1 - Question 10

What is the index range of elements in an array with 10 elements?

Detailed Solution for Test: Arrays - 1 - Question 10

The index range of elements in an array with 10 elements is from 0 to 9.

Test: Arrays - 1 - Question 11

What is the output of the following code snippet?
#include <iostream>
using namespace std;

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    cout << arr[2];
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 11

The code initializes an array with elements 1, 2, 3, 4, 5. Printing arr[2] will output 3.

Test: Arrays - 1 - Question 12

What is the output of the following code snippet?
#include <iostream>
using namespace std;

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    cout << arr[5];
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 12

The code tries to access the element at index 5, which is out of bounds for the array. This results in a runtime error.

Test: Arrays - 1 - Question 13

What is the output of the following code snippet?
#include <iostream>
using namespace std;

void modifyArray(int arr[]) {
    arr[0] = 100;
}

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    modifyArray(arr);
    cout << arr[0];
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 13

The code passes the array to the modifyArray() function, which modifies the first element to 100. Printing arr[0] will output 100.

Test: Arrays - 1 - Question 14

What is the output of the following code snippet?
#include <iostream>
using namespace std;

void printArray(int arr[], int size) {
    for (int i = 0; i < size; i++) {
        cout << arr[i] << " ";
    }
}

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    printArray(arr, 5);
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 14

The code calls the printArray() function to print all the elements of the array. The output will be 1 2 3 4 5.

Test: Arrays - 1 - Question 15

What is the output of the following code snippet?
#include <iostream>
using namespace std;

int binarySearch(int arr[], int left, int right, int key) {
    if (left <= right) {
        int mid = left + (right - left) / 2;
        if (arr[mid] == key)
            return mid;
        if (arr[mid] > key)
            return binarySearch(arr, left, mid - 1, key);
        return binarySearch(arr, mid + 1, right, key);
    }
    return -1;
}

int main() {
    int arr[] = {2, 4, 6, 8, 10};
    int key = 8;
    int result = binarySearch(arr, 0, 4, key);
    cout << result;
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 15

The code performs a binary search for the key element 8 in the given array. Since 8 is present at index 3, the output will be 3.

Test: Arrays - 1 - Question 16

What does the following code snippet do?
#include <iostream>
using namespace std;

int binarySearch(int arr[], int n, int key) {
    int low = 0, high = n - 1;
    while (low <= high) {
        int mid = low + (high - low) / 2;
        if (arr[mid] == key)
            return mid;
        if (arr[mid] < key)
            low = mid + 1;
        else
            high = mid - 1;
    }
    return -1;
}

int main() {
    int arr[] = {2, 4, 6, 8, 10};
    int key = 6;
    int result = binarySearch(arr, 5, key);
    cout << result;
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 16

The code implements binary search iteratively on a sorted array and returns the index of the key element if found. If the key element is not found, it returns -1.

Test: Arrays - 1 - Question 17

What does the following code snippet do?
#include <iostream>
using namespace std;

int binarySearch(int arr[], int low, int high, int key) {
    if (low <= high) {
        int mid = low + (high - low) / 2;
        if (arr[mid] == key)
            return mid;
        if (arr[mid] > key)
            return binarySearch(arr, low, mid - 1, key);
        return binarySearch(arr, mid + 1, high, key);
    }
    return -1;
}

int main() {
    int arr[] = {2, 4, 6, 8, 10};
    int key = 8;
    int result = binarySearch(arr, 0, 4, key);
    cout << result;
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 17

The code implements binary search recursively on a sorted array and returns the index of the key element if found. If the key element is not found, it returns -1.

Test: Arrays - 1 - Question 18

What does the following code snippet do?
#include <iostream>
using namespace std;

int binarySearch(int arr[], int n, int key) {
    int low = 0, high = n - 1;
    while (low <= high) {
        int mid = low + (high - low) / 2;
        if (arr[mid] == key)
            return mid;
        if (arr[mid] > key)
            high = mid - 1;
        else
            low = mid + 1;
    }
    return -1;
}

int main() {
    int arr[] = {2, 4, 6, 8, 10};
    int key = 6;
    int result = binarySearch(arr, 5, key);
    cout << result;
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 18

The code implements binary search iteratively on a sorted array and returns the index of the key element if found. If the key element is not found, it returns -1.

Test: Arrays - 1 - Question 19

What does the following code snippet do?
#include <iostream>
using namespace std;

int binarySearch(int arr[], int low, int high, int key) {
    if (low <= high) {
        int mid = low + (high - low) / 2;
        if (arr[mid] == key)
            return mid;
        if (arr[mid] < key)
            low = mid + 1;
        else
            high = mid - 1;
        return binarySearch(arr, low, high, key);
    }
    return -1;
}

int main() {
    int arr[] = {2, 4, 6, 8, 10};
    int key = 8;
    int result = binarySearch(arr, 0, 4, key);
    cout << result;
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 19

The code implements linear search iteratively on an unsorted array and returns the index of the key element if found. If the key element is not found, it returns -1.

Test: Arrays - 1 - Question 20

What does the following code snippet do?
#include <iostream>
using namespace std;

int binarySearch(int arr[], int left, int right, int key) {
    if (left <= right) {
        int mid = left + (right - left) / 2;
        if (arr[mid] == key)
            return mid;
        if (arr[mid] > key)
            return binarySearch(arr, left, mid - 1, key);
        return binarySearch(arr, mid + 1, right, key);
    }
    return -1;
}

int main() {
    int arr[] = {2, 4, 6, 8, 10};
    int key = 12;
    int result = binarySearch(arr, 0, 4, key);
    cout << result;
    return 0;
}

Detailed Solution for Test: Arrays - 1 - Question 20

The code implements binary search recursively on a sorted array and returns the index of the key element if found. If the key element is not found, it returns -1.

Information about Test: Arrays - 1 Page
In this test you can find the Exam questions for Test: Arrays - 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Arrays - 1, EduRev gives you an ample number of Online tests for practice

Top Courses for EmSAT Achieve

Download as PDF

Top Courses for EmSAT Achieve