C Programming Quiz

Quiz for C (Arrays)

Time left: 600 seconds

Q.1. What is an Array in C language ?

Select Your Option

No Explanation.

Q.2. How array is initialized in C ?

Select Your Option

The correct syntax for array initialization in C is data_type array_name[] = {array_elements}; . option B, C & D are incorrect because array declaration syntax is wrong. Only square brackets([]) must be used for declaring an array.

Q.3. What is the maximum size of an array in c ?

Select Your Option

There is no fixed limit to the size of an array in C.

Q.4. An array elements are always stored in ______ memory location?

Select Your Option

An array in C is a collection of items stored at contiguous memory locations and elements can be accessed randomly using indices of an array. They are used to store similar type of elements as in the data type must be the same for all elements.

Q.5. An array is a group of memory locations related by the fact that they all have the same name and the same type.

Select Your Option

No Explanation.

Q.6. An array Index starts with ?

Select Your Option

This means that the index is used as an offset. The first element of the array is exactly contained in the memory location that array refers, so it should be denoted as array[0]

Q.7. What will be printed after execution ?

#include <stdio.h>
void main()
{
    int a[10] = {1,2,3,4,5};
    printf("%d",a[5]);
}                       


Select Your Option

When an array is partially initialized at the time of declaration then the remaining elements of the array is initialized to 0 by default.

Q.8. Which of the following are true ?
1. The array int num[26]; can store 26 elements.
2. The expression num[1] designates the very first element in the array.
3. It is necessary to initialize the array at the time of declaration.
4. The declaration num[SIZE] is allowed if SIZE is a macro.

Select Your Option

Statement 1 & 4 are true, statement 2 is false as indexing starts from 0 so num[1] will give the second element of the array and 3rd Statement is also false.

Q.9. How to declare a 2D and 3D array in C?

Select Your Option

The Syntax for 2D array is data_type name[][] with 2 sqaure bracket pair([]) and for 3D is data_type name[][][] with 3 square bracket pair([]).

Q.10. What is the output of C program?

#include <stdio.h>
int main()
{
    float marks[3] = {90.5, 92.5, 96.5};
    int a=0;
    while(a<3)
    {
    	printf("%.2f,", marks[a]);
        a++;
    }
}                      


Select Your Option

0.2%f prints only two values after decimal points. So for every iteration the output with 2 values after decimal point are printed. It is allowed to use float values with arrays.

Q.11. What is the output of C program ?

int main()
{
    int a[3] = {10,12,14};
    int i=0;
    while(i<3)
    {
    	printf("%d ", i[a]);
        i++;
    }
}                      


Select Your Option

a[i] == i[a]. Use any notation to refer to array elements in C.

Q.12. Which of the following is correct way to access 8th element from an array with 100 element (arr[100]) ?

Select Your Option

Array index always starts with 0. So for accessing 8th element of array arr[7] is correct way.

Q.13. What is meaning of following declaration ?
int(*ptr)[10];

Select Your Option

No Explanation.

Q.14. What is the output of C program ?

#include <stdio.h>
void main()
{
    int a[5] = {1,2,3,4,5};
    int b = sizeof(a)/sizeof(a[0]);
    printf("%d" , b);
}                      


Select Your Option

The variable 'a' has 5 elements. The size of the float variable is 4 bytes. Hence 5 elements x 4 bytes = 20 bytes sizeof(arr[0]) is 4 bytes Hence 20/4 is 5 bytes Hence the output of the program is '5'.

Q.15. Predict the output of C program with arrays and pointers?

#include<stdio.h>
int main()
{
    int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
    int i,j;
    int x=0;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        { 
        	x +=a[i][j];
        }
    }
        printf("%d",x); 
}

Select Your Option

The Array is a 2D array with rows and column. The 1st for loop (for(i=0;i<3;i++)) gets the row and 2nd (for(j=0;j<3;j++)) gets the column and by those values each value of the array is iterated then it is added to variable 'x' , so for every iteration the value of array will add and then give the addition of all elements in the array.

Q.16. Predict the output of C program with arrays and pointers?

int main() 
{
    int a[3] = {20,30,40};
    int *p[3];
    p=&a;
    printf("%d", *p[2]);
}                    


Select Your Option

To point to an array, array pointer declaration should be like (*p)[3] with parantheses. It points to array of 3 elements. Hemce program will give a Compile Error.

Q.17. What is the output of C program with arrays and pointers?

int main()
{
    int a[4] = {5,6,7,8};
    int i;
    int n = sizeof(a)/sizeof(a[3]);
    for(i=n-1;i>=0;i--)
    {
    	printf("%d",a[i]);
    }
}                       


Select Your Option

The n value is 4 as sizeof(a) = 16 and sizeof(a[3]) = 4. In for loop the 1st value is 3 so at the 1st iteration the last value of the array will be displayed and then decrementation occurs this gives the reverse order of the array.

Q.18. An entire array is always passed by ___ to a called function.

Select Your Option

Arrays are passed by pointer by default when passing the entire array to a function. Passing by pointer is very similar to passing by reference.

Q.19. Guess the output of C Program with arrays and pointers ?

void change(int[]);
int main()
{
    int a[3] = {20,30,40};
    change(a);
    printf("%d %d", *a, a[0]);
}
void change(int a[])
{
 	a[0] = 10;
}
                   


Select Your Option

Notice that function change() is able to change the value of a[0] of main(). It uses Call By Reference. So changes in called function affected the original values.

Q.20. Guess the output of C Program with arrays and pointers ?

int main()
{
    int a[2] = {11};
    printf("%d",1[a]);
    return 0;
}                   


Select Your Option

The variable a[2] is declared as an integer array with size '3' i.e. a[0],a[1] and a[2] and it's first element is initialized to value '10'(means arr[0]=10) . a[1] and a[2] = garbage value or zero. For printf("%d", 1[a]); It prints the second element value of the variable a which is 0.

Instructions:-

  1. This Quiz is based on the concepts of Arrays in C
  2. Each correct answer will carry 2 points
  3. Once an option is selected you cannot select any other, So choose wisely
  4. Do not refresh the page as it will reset the quiz
  5. Once the time is up the quiz will automatically get submitted with no of Question responded
  6. Your total score alongwith your name will be shown after submission of the Quiz
  7. Wish you ALL THE BEST 👍👍

START

Results:-

Hi




Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post