Data Structure MCQ Exam 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: 424 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. 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 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".

Submit
Please wait...
About This Quiz
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... see moredata. 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. see less

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

Submit
3. 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
4. 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 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".

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

Submit
6. 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 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".

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

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

Submit
9. 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" 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.

Submit
10. 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 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".

Submit
View My Results

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

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
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the output of the code given below?...
What will be the output of the program ?...
What does the following declaration mean? int (*ptr)[10]
What is the output of the code given below?...
What is the output of the code given below?...
What is the output of the code given below?...
Consider a two dimensional array ...
What will be the output of the program if the array begins at 65486...
What will be the output of the program ? ...
What will be the output of the program ?...
Alert!

Advertisement