Programming for Problem Solving (3110003) MCQs

MCQs of Array & String

Showing 11 to 20 out of 35 Questions
11.
What is the output?

void main()
{
    int a[4]={5,6,7,8};
    printf("%d",a[4]);
}

(a) 5
(b) 6
(c) 8
(d) None of these
Answer:

Option (d)

12.
What is the output?

void main()
{
    int a[] = {1,2,3,4};
    int b[4] = {5,6,7,8};
    printf("%d,%d", a[0], b[0]);
}

(a) 1,5
(b) 0,0
(c) 2,6
(d) Compiler error
Answer:

Option (a)

13.
What is the output?

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

(a) 20 12 14
(b) 10 20 14
(c) 10 12 20
(d) Compiler error
Answer:

Option (b)

14.
If we need to store word "INDIA" then which is correct syntax?
(a) char name[6] = {"I","N","D","I","A"}
(b) char name[6] = {'I','N','D','I','A','\0'}
(c) char name[6] = {'I','N','D','I','A'}
(d) None of these
Answer:

Option (b)

15.
What happens when you try to access an array variable outside its size?
(a) Compiler error is thrown
(b) 1 value will be returned
(c) 0 value will be returned
(d) Some garbage value will be returned
Answer:

Option (d)

16.
How many elements will be declared if an array declared like below
int a[7];
(a) 6
(b) 7
(c) 8
(d) None of these
Answer:

Option (b)

17.
How many elements will be declared if an array declared like below
int a[3][4];
(a) 8
(b) 6
(c) 12
(d) 9
Answer:

Option (c)

18.
Which of the following is correct initialization?
(a) int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};
(b) int a[][2] = {{1,2},{3,4}};
(c) int a[3][3]={1,2,3,4,5,6,7,8,9};
(d) All of these
Answer:

Option (d)

19.
Which of the following is a two-dimensional array?
(a) array anarray[20][20];
(b) int anarray[20][20];
(c) int array[20, 20];
(d) char array[20];
Answer:

Option (b)

20.
What is the output?

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

(a) 0
(b) 1
(c) Garbage value
(d) Compiler error
Answer:

Option (a)

Showing 11 to 20 out of 35 Questions