Array In C programming MCQs: Multiple-Choice Questions

Array In C programming MCQs. Arrays Related Multiple-Choice Questions in C Programming. See all C language MCQs on all topics

Array In C programming

 

What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of the array ??

A. The element will be set to 0
B. The compiler would report an error
C. The program may crash if some important data gets overwritten
D. The array size would appropriately grow

 

What does the following declaration mean ??
int (*ptr)[10];

A. ptr is an 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 a pointer to an array

 

What will be the output of the program ??

#include<stdio.h>
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;
}

A. 2, 1, 15
B. 1, 2, 5
C. 3, 2, 15
D. 2, 3, 20

 

In C, if you pass an array as an argument to a function, what actually gets passed ??

A. Value of elements in the array
B. First element of the array
C. Base address of the array
D. Address of the last element of the array

Arrays

 

Which of the following statements mentioning the name of the array begins DOES NOT yield the base address ??
1: When array name is used with the sizeof operator.
2: When array name is an operand of the & operator.
3: When array name is passed to scanf() function.
4: When array name is passed to printf() function.

A. A
B. A, B
C. B
D. B, D

What will be the output of the program ??

#include<stdio.h>

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\n”, *(*(p+i)+j), *(*(j+p)+i),
*(*(i+p)+j), *(*(p+j)+i));
}
}
return 0;
}

A. 1, 1, 1, 1
2, 3, 2, 3
3, 2, 3, 2
4, 4, 4, 4

B. 1, 2, 1, 2
2, 3, 2, 3
3, 4, 3, 4
4, 2, 4, 2

C. 1, 1, 1, 1
2, 2, 2, 2
2, 2, 2, 2
3, 3, 3, 3

D. 1, 2, 3, 4
2, 3, 4, 1
3, 4, 1, 2
4, 1, 2, 3

 

Which of the following statements are correct about 6 in the code given ??
int num[6];
num[6]=21;

A. In the first statement, 6 specifies a particular element, whereas in the second statement it specifies a type
B. In the first statement 6 specifies an array size, whereas in the second statement it specifies a particular element of the array
C. In the first statement 6 specifies a particular element, whereas in the second statement it specifies an array size
D. In both the statement 6 specifies array size

 

What will be the output of the program ??

#include<stdio.h>
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\n”, **p);
}

A. 1
B. 2
C. 3
D. 4

Array In C programming

 

Which of the following statements are correct about an array ??
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

A. 1
B. 1,4
C. 2,3
D. 2,4

 

Does the array name give the base address in all the contexts ??

A. Yes
B. No

What will be the output of this program ??

#include<stdio.h>
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;

for(i=0; i<5; i++)
printf(“%d, “, arr[i]);

return 0;
}

A. 1, 2, 3, 4, 5,
B. Garbage value, 1, 2, 3, 4,
C. 0, 1, 2, 3, 4,
D. 2, 3, 4, 5, 6,

A pointer to a block of memory is effectively the same as an array ??

A. True
B. False

Array In C programming

 

What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes ??

#include<stdio.h>
int main()
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
printf(“%u, %u\n”, a+1, &a+1);
return 0;
}

A. 65474, 65476
B. 65480, 65496
C. 65480, 65488
D. 65474, 65488

 

Both declarations look similar but, is there any difference in these declarations ??
int fun(int arr[]);
int fun(int arr[2]);

A. Yes
B. No

 

What will be the output of the program ??

#include<stdio.h>
int main()
{
int arr[1]={10};
printf(“%d\n”, 0[arr]);
return 0;
}

A. 1
B. 10
C. 0
D. 6

 

Are the expressions arr and &arr the same for an array of 10 integers ??

A. Yes
B. No

Array In C programming

 

What will be the output of the program ??

#include<stdio.h>
int main()
{
float arr[] = {12.4, 2.3, 4.5, 6.7};
printf(“%d\n”, sizeof(arr)/sizeof(arr[0]));
return 0;
}

A. 5
B. 4
C. 6
D. 7

 

What is the effect of the following code ??

main()
{
int a[4]={1,5};
printf(“%d”,a[3]);
}

A. 0
B. Syntax error because of improper initialization
C. 5
D. Syntax error because of invalid index

 

The size of the array should always be ??

A. Positive
B. Negative
C. Whole number
D. Real number

 

What is the meaning of the following declaration ??

int arr[20];

A.Integer Array of size 20
B.None of these
C.An array of size 20 that can have an integer address
D.An array of Size 20

Array In C programming

 

For the following definition, which of the given option is correct ??

int a[10];

A. a++;
B. a=a+1
C. *a++
D. *a[1]

 

int a[50];
int *pa;
pa=a;

To access the 6th element of the array which of the following is incorrect ??

A. *(a+5)
B. a[5]
C. pa[5]
D. *(*pa+5)

 

More C Language Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!