Data Structure MCQ Exam Quiz!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Gauravkumar06201
G
Gauravkumar06201
Community Contributor
Quizzes Created: 2 | Total Attempts: 639
Questions: 10 | Attempts: 409

SettingsSettingsSettings
Data Structure MCQ Exam Quiz! - Quiz


Data structure is a compilation of data values, the relationships between them, and the roles or operations applied to the data. It is specialized for organizing and storing data. This quiz will show you what certain declarations mean, the output of the program, what are bytes, and what is a two-dimensional array. This quiz will shape the way you view data structure.


Questions and Answers
  • 1. 

    What is the output of the code given below? #include void main() { int arr[] = {10, 20, 30, 40, 50, 60}; int *ptr1 = arr; int *ptr2 = arr + 6; printf("Number of Elements : %d", (ptr2 - ptr1)); printf("Number of Bytes : %d", (char*)ptr2 - (char*) ptr1); }

    • A.

      Number of Elements : 5 Number of Bytes: 20

    • B.

      Number of Elements : 6 Number of Bytes: 24

    • C.

      Compile Time Error

    • D.

      Run Time Error

    Correct Answer
    B. Number of Elements : 6 Number of Bytes: 24
    Explanation
    The code declares an array "arr" with 6 elements. Two pointers "ptr1" and "ptr2" are assigned the address of the first element and the address of the element at index 6 respectively. The expression "(ptr2 - ptr1)" calculates the number of elements between the two pointers, which is 6. The expression "(char*)ptr2 - (char*)ptr1" calculates the number of bytes between the two pointers, which is 24. Therefore, the output of the code is "Number of Elements : 6 Number of Bytes: 24".

    Rate this question:

  • 2. 

    What will be the output of the program ? int main() { int a[5] = {5, 1, 15, 20, 25}; int i, j, m; i = ++a[1]; j = a[1]++; m = a[i++]; printf("%d, %d, %d", i, j, m); return 0; }

    • A.

      2, 1, 15

    • B.

      1, 2, 5

    • C.

      3, 2, 15

    • D.

      2, 3, 20

    Correct Answer
    C. 3, 2, 15
    Explanation
    The output of the program will be "3, 2, 15".

    In the program, the array "a" is initialized with values {5, 1, 15, 20, 25}.

    First, the value of a[1] is incremented by 1 using the prefix increment operator (++a[1]), so the value of a[1] becomes 2. This value is assigned to variable i.

    Next, the value of a[1] is incremented by 1 again using the postfix increment operator (a[1]++), so the value of a[1] becomes 3. This value is assigned to variable j.

    Then, the value of i (which is 2) is used as the index to access the element in array a, so m = a[2] which is 15.

    Finally, the values of i, j, and m are printed as "3, 2, 15".

    Rate this question:

  • 3. 

    What does the following declaration mean? int (*ptr)[10]

    • A.

      Ptr is array of pointers to 10 integers

    • B.

      Ptr is a pointer to an array of 10 integers

    • C.

      Ptr is an array of 10 integers

    • D.

      Ptr is an pointer to array

    Correct Answer
    B. Ptr is a pointer to an array of 10 integers
    Explanation
    The declaration "int (*ptr)[10]" means that "ptr" is a pointer to an array of 10 integers.

    Rate this question:

  • 4. 

    Consider a two dimensional array int A[100][100]; // assume that an integer requires 4 bytes. Starting address of the array is 5000 What is the address of the element A[4][5] if the allocation is row major ?

    • A.

      Address cannot be determined

    • B.

      5080

    • C.

      6620

    • D.

      6120

    Correct Answer
    C. 6620
    Explanation
    In a two-dimensional array allocated in row major order, the elements are stored in consecutive memory locations row by row. Since each integer requires 4 bytes, the address of A[4][5] can be calculated as follows:

    Starting address of the array = 5000
    Size of each row = 100 * 4 = 400
    Size of previous rows = 4 * 400 = 1600
    Size of previous columns in the same row = 5 * 4 = 20

    Therefore, the address of A[4][5] would be 5000 + 1600 + 20 = 6620.

    Rate this question:

  • 5. 

    What is the output of the code given below? #include void main() { float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5}; float *ptr1 = &arr[0]; float *ptr2 = ptr1 + 3; printf("%f ", *ptr2); printf("%d", ptr2 - ptr1);}

    • A.

      90.500000 3

    • B.

      90.500000 12

    • C.

      10.000000 12

    • D.

      0.500000 3

    Correct Answer
    A. 90.500000 3
    Explanation
    The code initializes an array of float values and assigns the memory address of the first element to ptr1. Then, ptr2 is assigned the memory address of the element at index 3 (90.5).

    In the first printf statement, *ptr2 is used to print the value at the memory address pointed by ptr2, which is 90.5.

    In the second printf statement, ptr2 - ptr1 is used to calculate the difference between the memory addresses pointed by ptr2 and ptr1. Since ptr2 is pointing to the element at index 3 and ptr1 is pointing to the element at index 0, the difference is 3.

    Therefore, the output of the code is "90.500000 3".

    Rate this question:

  • 6. 

    What will be the output of the program if the array begins at 65486 and each integer occupies 2 bytes? #include int main() { int arr[] = {12, 14, 15, 23, 45}; printf("%u, %u", arr+1, &arr+1); return 0; }

    • A.

      65488, 65490

    • B.

      64490, 65492

    • C.

      65488, 65496

    • D.

      64490, 65498

    Correct Answer
    C. 65488, 65496
    Explanation
    The program is using pointer arithmetic to print the memory addresses of the array elements.

    In the printf statement, arr+1 is used to print the memory address of the second element in the array. Since each integer occupies 2 bytes, the memory address of the second element would be 65486 + 2 = 65488.

    Similarly, &arr+1 is used to print the memory address of the element after the entire array. Since the array has 5 elements and each element occupies 2 bytes, the memory address of the element after the array would be 65486 + (5 * 2) = 65496.

    Therefore, the output of the program would be 65488, 65496.

    Rate this question:

  • 7. 

    What will be the output of the program ? #include int main() { static int a[2][2] = {1, 2, 3, 4}; int i, j; static int *p[] = {(int*)a, (int*)a+1, (int*)a+2}; for(i=0; i<2; i++) { for(j=0; j<2; j++) { printf("%d, %d, %d, %d", *(*(p+i)+j), *(*(j+p)+i), *(*(i+p)+j), *(*(p+j)+i)); } } return 0; }

    • A.

      1, 1, 1, 12, 3, 2, 33, 2, 3, 24, 4, 4, 4

    • B.

      1, 2, 1, 22, 3, 2, 33, 4, 3, 44, 2, 4, 2

    • C.

      1, 1, 1, 12, 2, 2, 22, 2, 2, 23, 3, 3, 3

    • D.

      1, 2, 3, 42, 3, 4, 13, 4, 1, 24, 1, 2, 3

    Correct Answer
    C. 1, 1, 1, 12, 2, 2, 22, 2, 2, 23, 3, 3, 3
    Explanation
    The program declares a static 2D array "a" with dimensions 2x2 and initializes it with values 1, 2, 3, and 4. It also declares a static array of pointers "p" that points to the elements of "a".

    In the nested for loop, the program prints the values of the elements in "a" using different combinations of pointer arithmetic.

    The output shows the values of the elements in "a" in a specific order: 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3.

    Rate this question:

  • 8. 

    What will be the output of the program ? #include void fun(int **p); int main() { int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; int *ptr; ptr = &a[0][0]; fun(&ptr); return 0; } void fun(int **p) { printf("%d", **p); }

    • A.

      1

    • B.

      2

    • C.

      3

    • D.

      4

    Correct Answer
    A. 1
    Explanation
    The program declares a 2D array 'a' with 3 rows and 4 columns. It then declares a pointer 'ptr' and assigns it the address of the first element of the array. The function 'fun' takes a double pointer as a parameter. In the main function, the address of 'ptr' is passed to 'fun'. Inside 'fun', the value at the address pointed by the double pointer is printed, which is the first element of the array 'a'. Therefore, the output of the program will be 1.

    Rate this question:

  • 9. 

    What is the output of the code given below? # include void fun(int *ptr) { *ptr = 30; } int main() { int y = 20; fun(&y); printf("%d", y); }

    • A.

      20

    • B.

      30

    • C.

      Compile Time error

    • D.

      Run Time error

    Correct Answer
    B. 30
    Explanation
    The code defines a function called "fun" that takes a pointer to an integer as a parameter. Inside the function, the value at the memory location pointed to by the pointer is changed to 30.

    In the main function, an integer variable y is declared and initialized to 20. Then, the function "fun" is called with the address of y as the argument. This means that the function will modify the value of y.

    Finally, the value of y is printed, which is now 30 because it was modified by the "fun" function.

    Rate this question:

  • 10. 

    What is the output of the code given below? #include void main()     { char *s= "hello"; char *p = s; printf("%c\t%c", *(p + 3),  s[1]);     }

    • A.

      H e

    • B.

      L l 

    • C.

      L o

    • D.

      L e

    Correct Answer
    D. L e
    Explanation
    The code initializes a character pointer variable 's' to point to the string "hello". Another character pointer variable 'p' is assigned the value of 's'. The printf statement then prints the character at the memory location pointed by 'p + 3', which is 'l', and the character at the index 1 of the string 's', which is 'e'. Therefore, the output of the code is "l e".

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 28, 2019
    Quiz Created by
    Gauravkumar06201
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.