Data Structure MCQ Test Quiz!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Gauravkumar06201
G
Gauravkumar06201
Community Contributor
Quizzes Created: 2 | Total Attempts: 654
| Attempts: 230 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. 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);
}

Explanation

The program defines a 2D array `a` and a pointer `ptr` that points to the first element of `a`. The function `fun` takes a double pointer as an argument. In the `main` function, the address of `ptr` is passed to `fun`. Inside `fun`, `**p` is used to access the value pointed to by `ptr`, which is the first element of `a`. Therefore, the output of the program will be 1.

Submit
Please wait...
About This Quiz
Data Structure MCQ Test Quiz! - Quiz


Looking for an interesting way to learn about data structure? Data structure is quite a difficult concept to grasp, as you can see from this quiz. Don't worry;... see morewith determination, this quiz will be helpful to you. For this quiz, you need to know the output of the code given, what an integer is, determine the program's production, and compile-time error. This quiz will be challenging, but you can do it. Go for it. see less

2. 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]);     }

Explanation

The code declares a character pointer 's' and assigns it the memory address of the string "hello". Another character pointer 'p' is then declared and assigned the value of 's'. The printf statement then prints the character at the memory location of 'p' plus 3 (which is 'l') and the character at the second index of the string 's' (which is 'e'). Therefore, the output of the code is "l e".

Submit
3. 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 ?

Explanation

In a row major allocation, the elements of a two-dimensional array 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 + (number of rows * row size) + (number of columns * element size)

5000 + (4 * 100 * 4) + (5 * 4) = 5000 + 1600 + 20 = 6620.

Therefore, the address of A[4][5] is 6620.

Submit
4. 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); }

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 assigned the value 20. Then, the address of "y" is passed as an argument to the "fun" function. This means that the value of "y" will be modified by the "fun" function. Finally, the value of "y" is printed, which will be 30 since it was modified by the "fun" function.

Submit
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);}

Explanation

The code initializes a float array `arr` with 5 elements. It then declares two float pointers `ptr1` and `ptr2`. `ptr1` is assigned the address of the first element of `arr`, and `ptr2` is assigned the address of the fourth element of `arr` (ptr1 + 3).

The first `printf` statement prints the value at the memory location pointed to by `ptr2`, which is 90.500000.

The second `printf` statement prints the difference between the two pointers `ptr2` and `ptr1`, which is 3. This is because `ptr2` is pointing to the fourth element of `arr`, and `ptr1` is pointing to the first element of `arr`, so there are 3 elements between them.

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

Explanation

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

Submit
7. 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); }

Explanation

The output of the code is "Number of Elements : 6 Number of Bytes: 24". This is because the difference between ptr2 and ptr1 gives the number of elements in the array, which is 6. The difference between the two pointers casted to char* gives the number of bytes between the two pointers, which is 24.

Submit
8. 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;
}

Explanation

The program declares a static 2D array 'a' and initializes it with the values 1, 2, 3, and 4. It also declares a static array of pointers 'p' which points to the rows of 'a'.

In the nested for loop, it prints the values of the elements in 'a' using the pointers in 'p'.

The first pointer *(*(p+i)+j) accesses the elements of 'a' row-wise.
The second pointer *(*(j+p)+i) accesses the elements of 'a' column-wise.
The third pointer *(*(i+p)+j) accesses the elements of 'a' column-wise.
The fourth pointer *(*(p+j)+i) accesses the elements of 'a' row-wise.

The output will be the values of the elements in 'a' printed in a specific pattern: 1, 1, 1, 12, 2, 2, 22, 2, 2, 23, 3, 3, 3.

Submit
9. 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;
}

Explanation

The program initializes an array `a` with values {5, 1, 15, 20, 25}.

- `i` is incremented by 1 and assigned the value of `a[1]`, which is 2. So, `i` becomes 3.
- `j` is assigned the value of `a[1]`, which is 2, and then `a[1]` is incremented by 1. So, `j` becomes 2.
- `m` is assigned the value of `a[i++]`, which is `a[3]`, which is 20. But since `i` is incremented after the assignment, `i` becomes 4.
- The `printf` statement prints the values of `i`, `j`, and `m`, which are 3, 2, and 20 respectively.

Therefore, the output of the program is "3, 2, 20".

Submit
10. 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;
}

Explanation

The program is printing the memory addresses of the second element in the array and the address immediately after the end of the array. Since each integer occupies 2 bytes in memory, the address of the second element would be 2 bytes higher than the starting address of the array. Similarly, the address immediately after the end of the array would be 2 bytes higher than the address of the last element. Therefore, the output of the program would be 65488 (65486 + 2) and 65496 (65486 + 5 * 2).

Submit
View My Results

Quiz Review Timeline (Updated): Mar 20, 2023 +

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

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 27, 2019
    Quiz Created by
    Gauravkumar06201
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What will be the output of the program ? ...
What is the output of the code given below? ...
Consider a two dimensional array ...
What is the output of the code given below? ...
What is the output of the code given below? ...
What does the following declaration mean? int (*ptr)[10]
What is the output of the code given below?...
What will be the output of the program ? ...
What will be the output of the program ?...
What will be the output of the program if the array begins at 65486...
Alert!

Advertisement