Arrays in C Programming MCQ Questions and Answers

Q1. Which of the following correctly declares a one-dimensional array of 50 integers in C?
A) int a(50);
B) int a[50];
C) int a = [50];
D) int a{50};
Answer: B

Q2. Given int a[10];, what is the valid index range for accessing elements?
A) 0 to 9
B) 1 to 10
C) -1 to 8
D) 0 to 10
Answer: A

Q3. If int a[5] = {1}; what are the values of the array elements?
A) {1,0,0,0,0}
B) {1,1,1,1,1}
C) {0,0,0,0,1}
D) Garbage values
Answer: A

Q4. Which expression yields the total number of elements in an array int a[20]; inside the same scope?
A) sizeof(a)
B) sizeof(a)/sizeof(int)
C) sizeof(a[0])
D) sizeof(int)/sizeof(a)
Answer: B

Q5. In C, an array name used in an expression typically decays to:
A) a copy of the array
B) pointer to its first element
C) pointer to the last element
D) size of the array
Answer: B

Q6. For int a[10];, the expression *(a + 3) is equivalent to:
A) a[2]
B) a[3]
C) &a[3]
D) 3[a]
Answer: B

Q7. Which of the following is valid for passing a 1D array to a function?
A) void f(int a[])
B) void f(int *a)
C) void f(int a[10])
D) All of the above
Answer: D

Q8. Which statement about sizeof applied to an array when passed to a function is true?
A) sizeof returns the number of elements in the array inside the function.
B) sizeof returns size of pointer, not array, inside function.
C) sizeof returns zero inside function.
D) sizeof behavior is undefined inside function.
Answer: B

Q9. Given int a[3][4];, the type of a when used in an expression (after decay) is:
A) int *
B) int **
C) int (*)[4]
D) int[3][4]
Answer: C

Q10. Which of the following initializes a 2×3 array int a[2][3] with all zeros?
A) int a[2][3] = {0};
B) int a[2][3] = { {0}, {0} };
C) memset(a, 0, sizeof(a));
D) All of the above
Answer: D

Q11. For int a[5] = {2,4,6};, what is a[3]?
A) 2
B) 4
C) 6
D) 0
Answer: D

Q12. Which declaration creates an array of pointers to integers?
A) int *a[10];
B) int (*a)[10];
C) int a*[10];
D) int a[10]*;
Answer: A

Q13. Which statement is true about variable-length arrays (VLA) in standard C99?
A) Their size must be a compile-time constant.
B) They can be declared with a runtime-determined size.
C) They are not allowed by C99.
D) They behave like pointers and must be freed.
Answer: B

Q14. Which function correctly allocates memory for an array of 100 int using dynamic allocation?
A) int *p = malloc(100);
B) int *p = malloc(100 * sizeof(int));
C) int *p = calloc(100);
D) int *p = realloc(NULL, 100);
Answer: B

Q15. After int *p = malloc(10 * sizeof *p);, which is the correct way to free it?
A) delete p;
B) free(p);
C) dispose(p);
D) release(p);
Answer: B

Q16. What does int (*p)[10]; declare p as?
A) pointer to int
B) pointer to array of 10 ints
C) array of 10 pointers
D) pointer to pointer to int
Answer: B

Q17. For a 2D array int a[3][4];, the expression a[1] has type:
A) int *
B) int[4] (decays to int *)
C) int **
D) int
Answer: B

Q18. Which code correctly copies 10 integers from src to dst?
A) memcpy(dst, src, 10);
B) memcpy(dst, src, 10 * sizeof(int));
C) strcpy(dst, src);
D) dst = src;
Answer: B

Q19. Given char s[] = “Hello”;, what is sizeof(s)?
A) 5
B) 6
C) sizeof(char)
D) Undefined
Answer: B

Q20. Which is true for char *s = “Hello”;?
A) The string literal is modifiable.
B) s[0] = ‘h’; is undefined behavior.
C) sizeof(s) equals 6.
D) s and char s[] = “Hello”; are identical in storage.
Answer: B

Q21. Which of the following will NOT compile?
A) int a[] = {1, 2, 3};
B) int a[3] = {1, 2, 3};
C) int a[2] = {1, 2, 3};
D) int a[3] = {1, 2};
Answer: C

Q22. In C, 3[a] is equivalent to:
A) Error
B) a[3]
C) &a[3]
D) *(a) + 3
Answer: B

Q23. Which operation is undefined when accessing arrays?
A) Accessing element a[0] in int a[1];
B) Accessing a[1] in int a[1];
C) Using pointer arithmetic within array bounds
D) Iterating from 0 to n-1 for int a[n];
Answer: B

Q24. Which approach correctly passes a 2D array to a function (known row size = 4)?
A) void f(int a[][4])
B) void f(int **a)
C) void f(int a[4][4])
D) void f(void *a)
Answer: A

Q25. Which is a safe way to initialize all elements of an int a[100] to -1?
A) int a[100] = {-1};
B) memset(a, -1, sizeof a);
C) Loop for(i=0;i<100;i++) a[i] = -1;
D) Both C and D are safe? (note: option listing mismatch — assume correct options below)
Answer: C

Q26. For int a[5];, which of these yields the address of the entire array (type int (*)[5])?
A) a
B) &a
C) &a[0]
D) a + 1
Answer: B

Q27. Consider int a[3] = {1,2,3}; int *p = a + 1;. What does p[-1] give?
A) 3
B) 2
C) 1
D) Undefined
Answer: C

Q28. Which statement about memcpy and overlapping memory is correct?
A) memcpy handles overlaps correctly.
B) memmove should be used for overlapping regions.
C) Overlaps are allowed with memcpy if sizes match.
D) Both memcpy and memmove behave the same with overlap.
Answer: B

Q29. What is the effect of int a[0]; in standard C (strictly conforming)?
A) Valid zero-length array (standard)
B) Compiler error in standard C (C99 disallows as object)
C) Creates an array with one element
D) Equivalent to int *a;
Answer: B

Q30. Given int a[10];, pointer p = a; and q = a + 10; what is q – p?
A) 9
B) 10
C) Size in bytes between q and p
D) Undefined
Answer: B

Q31. The expression sizeof(a)/sizeof(a[0]) gives the number of elements only when:
A) a is a pointer
B) a is an array in the same scope where sizeof is used
C) a is dynamic memory
D) Always true
Answer: B

Q32. Which will correctly sort an int arr[] of length n using standard library?
A) qsort(arr, n, sizeof(int), cmp); with a compatible cmp function
B) sort(arr, arr+n);
C) qsort(arr, n, sizeof(int), NULL);
D) qsort(arr, sizeof(arr), n, cmp);
Answer: A

Q33. For int arr[4] = {0,1,2,3};, evaluating *(arr+4) is:
A) 3
B) 0
C) Undefined (out-of-bounds dereference)
D) Address of arr[4]
Answer: C

Q34. Which declaration declares a function parameter that accepts any-size 2D array with columns known at compile time?
A) void f(int a[][N]); where N is compile-time constant
B) void f(int **a);
C) void f(int a[N][]);
D) void f(int a[][]);
Answer: A

Q35. Which is true about multidimensional arrays in C?
A) They are arrays of arrays stored contiguously in row-major order.
B) They are arrays of pointers by default.
C) The rows can have different sizes when declared as int a[3][4];.
D) Column-major order storage is used.
Answer: A

Q36. What happens when you assign arrays like int a[3]; int b[3]; a = b;?
A) Copies contents of b into a
B) Causes compile-time error (arrays are not assignable)
C) Makes a point to b’s storage
D) Undefined at runtime
Answer: B

Q37. For char str[] = “abc”; char *p = str;, the expression sizeof(p) typically returns:
A) 3
B) 4
C) size of pointer (e.g., 8 on 64-bit)
D) size of entire string including null terminator
Answer: C

Q38. Which of these correctly declares a static array that persists across function calls?
A) static int a[10]; inside function
B) int a[10]; inside function
C) int a[10] declared in main and used elsewhere without extern
D) register int a[10];
Answer: A

Q39. Which of the following is true about memset for setting an int array to -1?
A) It will set each byte to 0xFF, yielding -1 for two’s complement ints only.
B) It sets each int element correctly on all platforms.
C) It is undefined behavior for non-char arrays.
D) It sets each element to -1 by calling assignment.
Answer: A

Q40. Which would correctly declare a function that returns a pointer to an array of 5 ints?
A) int (*f())[5];
B) int *f()[5];
C) int f()[5];
D) int (*f)[5]();
Answer: A

Q41. Which of the following is true regarding array indexing a[i] in terms of pointer arithmetic?
A) a[i] is equivalent to *(a + i)
B) a[i] is equivalent to *(i + a)
C) Both A and B
D) Neither A nor B
Answer: C

Q42. Which of the following yields the number of rows of int a[5][10]; using sizeof?
A) sizeof(a) / sizeof(a[0])
B) sizeof(a[0]) / sizeof(a)
C) sizeof(a[0]) / sizeof(a[0][0])
D) sizeof(a) / sizeof(a[0][0])
Answer: A

Q43. Which technique safely initializes a dynamically allocated array to zero?
A) malloc(n * sizeof *p); then memset to 0
B) calloc(n, sizeof *p);
C) malloc with for loop to set zeros
D) Any of the above
Answer: D

Q44. For int a[4] = {1,2,3,4};, what is the type of &a[0]?
A) int
B) int *
C) int (*)[4]
D) void *
Answer: B

Q45. Which is the correct way to declare a jagged 2D array dynamically (rows with differing lengths)?
A) Allocate array of pointers to int, then allocate each row separately.
B) Use int a[rows][cols]; with varying cols per row.
C) Use int **a; and treat directly as 2D contiguous storage.
D) Not possible in C.
Answer: A

Q46. Given int a[5];, what is the result type of a + 1?
A) int
B) int *
C) int **
D) void *
Answer: B

Q47. Which statement about const and arrays is true?
A) const int a[5] makes elements modifiable.
B) int const *p means pointer to constant integers.
C) int * const p means pointer to mutable ints but pointer itself is constant.
D) Both B and C are true.
Answer: D

Q48. Which of the following is allowed in C regarding array sizes?
A) Negative array size at compile time
B) Zero-length arrays in standard C (except as GCC extension)
C) Variable-length arrays inside functions (C99)
D) Both B and C as standard features
Answer: C

Q49. What will be printed by:
int a[3] = {1,2,3};
printf(“%p %p\n”, (void*)a, (void*)&a);
A) Two identical addresses
B) Different addresses (a points to element 0 and &a to array)
C) Compiler error
D) Undefined behavior
Answer: A

Q50. Which function signature can accept both int a[] and int *a callers?
A) void f(int a[])
B) void f(int *a)
C) void f(int a[10])
D) All of the above
Answer: D

Q51. If int a[10];, which expression is permitted but dangerous (undefined behavior)?
A) a[10] = 0;
B) a[9] = 0;
C) *(a + 9) = 0;
D) a[0] = 0;
Answer: A

Q52. Which of these is the correct prototype for a function that accepts an array of pointers to char?
A) void f(char *a[])
B) void f(char **a)
C) void f(const char *a[])
D) All of the above (depending on const)
Answer: D

Q53. In C, string literals have type:
A) char *
B) const char * (since they should not be modified)
C) char[] modifiable
D) int
Answer: B

Q54. Which statement about pointer-to-array and pointer-to-pointer is correct?
A) int (*p)[10] and int **p are interchangeable.
B) int (*p)[10] points to contiguous 10-int blocks, different from int **.
C) int **p points to contiguous 10-int blocks.
D) All are equivalent.
Answer: B

Q55. Which of the following dynamic allocation calls is most appropriate for double array of length n to ensure zero initialization?
A) malloc(n * sizeof(double))
B) calloc(n, sizeof(double))
C) realloc(NULL, n * sizeof(double))
D) malloc(n)
Answer: B

Q56. Which statement about array subscripting beyond the declared size but inside the same allocated block (e.g., dynamic allocation larger than declared) is true?
A) Always safe
B) Undefined unless allocation supports it and pointer arithmetic used carefully
C) Defined only for static arrays
D) Not possible in C
Answer: B

Q57. What is the output of:
int a[] = {10,20,30};
printf(“%d\n”, *(a + 1));
A) 10
B) 20
C) 30
D) Undefined
Answer: B

Q58. Which of the following is true when using realloc on a pointer returned by malloc?
A) realloc may move the block and return new pointer.
B) Old pointer becomes invalid if realloc returns new pointer.
C) realloc can shrink or expand the allocation.
D) All of the above.
Answer: D

Q59. When passing an array to a function intending to change its size, which is correct?
A) You can change array size inside the function and caller sees it automatically.
B) Use dynamic allocation and pass pointer by reference (pointer to pointer) or return new pointer.
C) Use a local VLA and caller sees it.
D) Static arrays can be resized implicitly.
Answer: B

Q60. Consider:
int a[2][3] = {{1,2,3},{4,5,6}};
int *p = &a[0][0];
What is p[4]?
A) 4
B) 5
C) 6
D) Undefined
Answer: B

Q61. Which is the correct way to pass the length of an array to a function so the function can iterate safely?
A) Rely on sizeof inside the function.
B) Pass the pointer only.
C) Pass both pointer and its length as separate parameters.
D) Use global variable size always.
Answer: C

Q62. What does this declaration mean: extern int a[];?
A) Defines an array a of unknown size with external linkage (definition must appear elsewhere).
B) Allocates memory for a.
C) Declares a pointer to int.
D) Invalid declaration.
Answer: A

Q63. Which of the following is true about memset applied to a double array to set elements to 0.0?
A) It is safe and portable.
B) It works because zero representation is all-bits-zero on all platforms.
C) It is generally safe in practice but portability depends on IEEE representation—C guarantees zero initialization via assignment or calloc.
D) memset sets doubles to -0.0.
Answer: C

Q64. For int x = 1; int a[] = {x};, which is true?
A) Compile-time constant required for initialization.
B) Initialization with non-constant is allowed in C for automatic arrays.
C) Only constant expressions allowed for any array initializer.
D) This code is invalid.
Answer: B

Q65. What is the result of:
char s[] = “A”;
printf(“%zu\n”, sizeof(s));
A) 0
B) 1
C) 2
D) Undefined
Answer: C

Q66. Given int a[4] = {0,1,2,3};, which of the following rotates elements right by one using pointer arithmetic safely?
A) Use temp = a[3]; memmove(a+1, a, 3*sizeof a); a[0]=temp;
B) Use memcpy for overlapping memory from end to start.
C) Use memcpy(a+1, a, 3sizeof *a); // safe for overlap
D) Use strcpy on integer arrays
Answer: A

Q67. Which statement about initialization int a[5] = { [2] = 10 }; (designated initializer) is true in C?
A) It’s a GNU extension only.
B) Designated initializers are standard in C99 and later.
C) It sets all elements to 10.
D) It is illegal syntax.
Answer: B

Q68. Which option declares a multidimensional array where memory is contiguous for all rows?
A) int a[3][4];
B) int *a[3]; with separate allocations per row
C) int **a; allocated with one malloc for all elements but used as ** incorrectly
D) None of the above
Answer: A

Q69. What is the behaviour of free when passed NULL?
A) Crash
B) Undefined behavior
C) No operation (safe)
D) Frees memory at address 0
Answer: C

Q70. For int a[2][3];, the expression &a[1] – &a[0] yields:
A) 1 (difference in number of rows)
B) 3 (difference in columns)
C) Size in bytes between rows
D) Undefined
Answer: A

Q71. Which of the following is true about strncpy used on character arrays?
A) Always null-terminates the destination.
B) May not null-terminate if source length >= n.
C) Is safer than strcpy in all cases.
D) Copies until destination buffer ends and appends null automatically.
Answer: B

Q72. What is the correct declaration for a function that accepts a pointer to the first element of a 3×4 int matrix stored contiguously?
A) void f(int *m) and interpret with index [i*4 + j]
B) void f(int m[3][4])
C) void f(int *m[3])
D) Both A and B are feasible depending on usage
Answer: D

Q73. Which of these is true on modern C programs regarding stack allocation of large arrays?
A) Always safe—stack size unlimited.
B) May cause stack overflow if array is too large; prefer dynamic allocation.
C) Compiler automatically moves large arrays to heap.
D) Global arrays are always stored on stack.
Answer: B

Q74. What does int arr[] = { [1]=10, [3]=20 }; initialize arr as?
A) Illegal syntax
B) {0,10,0,20} with length at least 4
C) {10,20}
D) {1,3}
Answer: B

Q75. Which of the following operations is valid on array function parameters?
A) sizeof to get number of elements reliably
B) pointer arithmetic like p + i
C) assignment p = some_other_array if parameter declared as int a[]
D) both B and C (assignment allowed if parameter is declared as pointer)
Answer: D

Q76. Which of the following is true about arrays inside structures?
A) Arrays in structs can be initialized using designated initializers.
B) sizeof a struct with an array accounts for the array size.
C) Arrays inside structs contribute to the struct’s size and alignment.
D) All of the above.
Answer: D

Q77. For int a[5] = {1,2,3,4,5};, what does sizeof(a) / sizeof a[0] produce?
A) 4
B) 5
C) Size in bytes
D) Undefined
Answer: B

Q78. Which is correct to compare two arrays for equality of contents?
A) Use == operator.
B) Use memcmp(a, b, sizeof a) == 0.
C) Use strcmp(a,b) for integer arrays.
D) Arrays cannot be compared.
Answer: B

Q79. For int *p = malloc(5 * sizeof *p); what is p[5]?
A) Valid and contains next allocated element
B) Out-of-bounds access (undefined)
C) Equivalent to *(p + 5) which is last element
D) Zero-initialized
Answer: B

Q80. Which is true for array initializers with fewer elements than declared?
A) Remaining elements are zero-initialized.
B) Remaining elements are undefined.
C) Compiler error.
D) Remaining elements are set to -1.
Answer: A

Q81. Which statement is correct about static local arrays?
A) They have automatic storage duration.
B) They are allocated on stack per call.
C) They preserve values between function calls.
D) They must be freed by programmer.
Answer: C

Q82. Which of the following correctly reserves space for m*n integers as a contiguous block dynamically?
A) int *p = malloc(m * n * sizeof *p);
B) int **p = malloc(m * sizeof *p); for(i) p[i]=malloc(n*sizeof **p);
C) int (*p)[n] = malloc(m * sizeof *p); (if n known at compile-time or VLA)
D) Any of the above depending on requirement, but A and C give contiguous block.
Answer: D

Q83. Which operation on an array is not allowed in C?
A) Passing it to a function by pointer
B) Copying it with memcpy
C) Using bracket indexing
D) Using assignment arr1 = arr2 for two arrays declared as objects
Answer: D

Q84. What is the effect of int a[3] = { [0] = 1, [2] = 3 };?
A) {1,0,3}
B) {1,3,0}
C) Error—designated indexes not allowed
D) {0,1,3}
Answer: A

Q85. Which statement about arrays and volatile qualifier is true?
A) volatile int a[10]; makes elements volatile (compiler won’t optimize accesses).
B) volatile only applies to pointer, not array.
C) volatile has no effect on arrays.
D) volatile automatically synchronizes threads.
Answer: A

Q86. Which of the following will correctly compute the number of elements in int a[10] when a is global?
A) sizeof(a)/sizeof(a[0]) in any file where a is defined with full type
B) sizeof(a)/sizeof(a[0]) in a file that only has extern int a[]; declaration
C) sizeof works across translation units with extern reference
D) None of above
Answer: A

Q87. For a 2D array int a[4][4], which pointer arithmetic accesses element (2,1)?
A) *(*(a + 2) + 1)
B) a[2][1]
C) Both A and B
D) *(a + 2) + 1 only
Answer: C

Q88. What is the value of *( (int[]){1,2,3} + 1 ) (compound literal) in C99?
A) 1
B) 2
C) 3
D) Undefined
Answer: B

Q89. Which of the following best describes flexible array members in structs?
A) Declaring last member as int arr[]; to allow variable-sized object at end (C99).
B) Declaring int arr[0]; is standard-compliant.
C) They must be used only as static arrays.
D) They require manual copying for each access.
Answer: A

Q90. Which is true about using fread to read binary array of ints from file?
A) Use fread(a, sizeof(int), n, fp); to read n elements.
B) Use fread(a, n, sizeof(int), fp); order wrong.
C) Use fread(&a, sizeof a, fp); for reading array.
D) Do not use fread for arrays.
Answer: A

Q91. Which of the following accesses are valid if p points to first element of arr and arr has length n?
A) p + n (pointer one past end) is allowed but not dereferenced.
B) Dereferencing *(p + n) is allowed.
C) p – 1 is allowed if p points to arr start.
D) All pointer arithmetic must remain within [arr, arr+n] inclusive for deref.
Answer: A

Q92. Which is true about arrays of structures?
A) All structure elements are stored contiguously according to struct size including padding.
B) Each structure element may be stored non-contiguously.
C) Accessing struct array elements with pointer arithmetic is undefined.
D) sizeof(struct_arr) equals N * sizeof(struct) for N elements always ignoring padding.
Answer: A

Q93. What is the behavior of directly returning a pointer to a local (non-static) array from a function?
A) Safe — caller gets valid pointer.
B) Undefined behavior — pointer refers to stack memory that goes out of scope.
C) Compiler error.
D) Automatic copying to caller.
Answer: B

Q94. Which approach will correctly implement a dynamic 2D array with contiguous storage and indexable via a[i][j] when j is compile-time constant?
A) int (*a)[COLS] = malloc(rows * sizeof *a);
B) int **a = malloc(rows * sizeof *a); and allocate each row separately
C) Use malloc(rows*cols*sizeof(int)) and access with manual indexing a[i*cols+j]
D) All are correct, only A gives direct a[i][j] syntax with contiguous block and pointer-of-array type.
Answer: D

Q95. Which is true about initialization of global arrays?
A) If not initialized explicitly, they are zero-initialized.
B) They contain garbage if not initialized.
C) They must be initialized.
D) Their elements are set to -1 by default.
Answer: A

Q96. Which of the following indicates the array was allocated on the heap?
A) It was declared as global.
B) It was created using malloc/calloc/realloc.
C) It was declared as local array in function.
D) It was declared as static local array.
Answer: B

Q97. Which of the following best describes sizeof operator on function parameter declared as int a[]?
A) Returns size of array elements.
B) Returns size of pointer on that platform.
C) Returns zero.
D) Returns number of elements times size of element.
Answer: B

Q98. Consider int a[3] = {1,2}; what is the value of a[2]?
A) 1
B) 2
C) 0
D) Indeterminate (garbage)
Answer: C

Q99. Which of the following is a correct way to copy a subarray of length k starting at index i from src to dst (non-overlapping)?
A) memcpy(dst, src + i, k * sizeof *src);
B) copy(dst, src + i, k);
C) strcpy(dst, src + i);
D) dst = src + i;
Answer: A

Q100. Which of the following statements about arrays and pointers is FALSE?
A) Array name may be used where a pointer to its first element is expected.
B) Pointer arithmetic moves in units of the pointed-to type.
C) sizeof an array equals number of elements times sizeof element in the scope where array object is visible.
D) Pointer to an array int (*)[n] is same as int ** for all practical usages.
Answer: D