# Data Structure MCQ Test 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.
| By Gauravkumar06201
G
Gauravkumar06201
Community Contributor
Quizzes Created: 2 | Total Attempts: 586
Questions: 10 | Attempts: 204  Settings  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; with 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.

• 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

B. Number of Elements : 6 Number of Bytes: 24
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.

Rate this question:

• 2.

### What will be the output of the program ? int main() { int a = {5, 1, 15, 20, 25}; int i, j, m; i = ++a; j = a++; 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

C. 3, 2, 15
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`, which is 2. So, `i` becomes 3.
- `j` is assigned the value of `a`, which is 2, and then `a` is incremented by 1. So, `j` becomes 2.
- `m` is assigned the value of `a[i++]`, which is `a`, 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".

Rate this question:

• 3.

### What does the following declaration mean? int (*ptr)

• 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

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

Rate this question:

• 4.

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

• A.

• B.

5080

• C.

6620

• D.

6120

C. 6620
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 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 is 6620.

Rate this question:

• 5.

### What is the output of the code given below? #include void main() { float arr = {12.5, 10.0, 13.5, 90.5, 0.5}; float *ptr1 = &arr; 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

A. 90.500000 3
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.

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

C. 65488, 65496
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).

Rate this question:

• 7.

### What will be the output of the program ? #include int main() { static int a = {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

C. 1, 1, 1, 12, 2, 2, 22, 2, 2, 23, 3, 3, 3
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.

Rate this question:

• 8.

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

• A.

1

• B.

2

• C.

3

• D.

4

A. 1
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.

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

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 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.

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

• A.

H e

• B.

L l

• C.

L o

• D.

L e

D. L e
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".

Rate this question:

Related Topics Back to top