Need Help or More Information?
Questions about this free C programming course, embedded C training or career guidance? Get in touch.
C Arrays Quiz and Interview
Test yourself with a C arrays quiz: 10 MCQs, output prediction, programming challenges and interview questions with answers for embedded C roles.
This is the practice lecture of our free C programming course arrays chapter. Here you will find a quiz with answers, output puzzles and the most common C arrays interview questions that firmware recruiters ask.
All outputs shown in the answers come from programs that were compiled and executed, so you can trust them. Use this page as a checklist before a written test or a campus placement interview.
What You Will Learn
- Ten multiple choice questions on initialization, copying, searching and function calls
- Output prediction on partial initialization, loops and call by value
- Four programming challenges with hints
- Twelve C arrays interview questions with model answers
- A common mistakes recap you can revise in minutes
Prerequisites
- Lectures 6 to 11 of this arrays chapter
- A C compiler to check your answers
- Pen and paper to predict outputs before running code
Recap: What These C Array Lectures Covered
Your C arrays toolkit after this chapter
This final lecture of the set is a self test. Try every question on paper or in your compiler before you open the answer. The questions are written in the style of campus tests and entry-level embedded interviews, so treat this page as a rehearsal for real C arrays interview questions.
| Your score out of 10 (quiz A) | What to do next |
|---|---|
| 0 to 4 | Re-read lectures 6 and 7, then retry the quiz tomorrow |
| 5 to 8 | Good. Revisit the questions you missed and run the matching program |
| 9 to 10 | Excellent. Move on to the programming challenges |
C Arrays Interview Questions, Part A: Ten MCQs
A local array
int a[4];is declared insidemain()and never written. What does it contain?- A. Four zeros
- B. Indeterminate values
- C. Four values of -1
- D. The program will not compile
Show answer
B. Local arrays live on the stack and are not cleared. Reading them before writing is a bug.
Given
int a[5] = {9};, what isa[3]?- A. 9
- B. Garbage
- C. 0
- D. Compile error
Show answer
C. Elements without an initializer are set to zero. Only
a[0]is 9.What does
sizeof m / sizeof m[0]give forint m[] = {4, 7, 1};?- A. 1
- B. 3
- C. 12
- D. 4
Show answer
B. The array has 3 elements. The division of total bytes by element bytes returns the element count, whatever the size of int is.
Which statement will not compile when
aandbare bothint[5]arrays?- A.
memcpy(a, b, sizeof b); - B.
a = b; - C. A for loop copying b[i] to a[i]
- D. All three compile
Show answer
B. An array is not assignable as a whole. The other two forms copy the elements correctly.
- A.
The temperatures are -12, -7, -30, -3 and -18. A program seeds
max = 0and scans for a larger value. What does it print?- A. -3
- B. 0
- C. -30
- D. -12
Show answer
B. Zero is larger than every element, so max is never replaced. Seed from a real element such as the first one.
How many swaps are needed to reverse a 9-element array in place?
- A. 9
- B. 5
- C. 4
- D. 8
Show answer
C. N/2 rounded down is 4. The fifth element is in the middle and stays where it is.
For
for (i = 0, j = 9; i < j; i++, j--)with a 10-element array, what are i and j when the loop stops?- A. i=4, j=5
- B. i=5, j=4
- C. i=5, j=5
- D. i=10, j=-1
Show answer
B. After the swap of indices 4 and 5 the counters become i=5 and j=4, so the test i < j fails.
What is 45 in binary?
- A. 101011
- B. 110100
- C. 101101
- D. 100111
Show answer
C. 32 + 8 + 4 + 1 = 45, which is 101101.
What is the worst case number of comparisons for linear search in a 50-element array?
- A. 1
- B. 6
- C. 25
- D. 50
Show answer
D. A missing value or one in the last slot needs all 50 comparisons. The average for a present value is about 25.
After
void f(int x) { x = 0; }and the callf(a[1]);, what is true?- A. a[1] becomes 0
- B. a[1] is unchanged
- C. The whole array becomes 0
- D. The program does not compile
Show answer
B. The function received a copy of the value of a[1], so the original element is untouched.
C Arrays Interview Questions, Part B: Predict the Output
Do not run the code first. Write your answer, then open the answer to see the real output from a compiled program.
Question 1: partial initialization
#include <stdio.h> int main(void) { int a[5] = {1, 2}; printf("%d %d %d\n", a[0], a[1], a[4]); return 0; }Show answer
The array is
{1, 2, 0, 0, 0}, so a[4] is 0. Real output:1 2 0Question 2: a loop that stops early
#include <stdio.h> int main(void) { int a[6] = {1, 2, 3, 4, 5, 6}; int i, j, t; for (i = 0, j = 3; i < j; i++, j--) { t = a[i]; a[i] = a[j]; a[j] = t; } for (i = 0; i < 6; i++) printf("%d ", a[i]); printf("\n"); return 0; }Show answer
The loop swaps indices 0 and 3, then 1 and 2, then stops because i is no longer below j. Elements 4 and 5 are never touched. Real output (note the trailing space):
4 3 2 1 5 6Question 3: the counter after a failed search
#include <stdio.h> int main(void) { int a[3] = {5, 10, 15}; int i; for (i = 0; i < 3; i++) if (a[i] == 20) break; printf("%d\n", i); return 0; }Show answer
No element equals 20, so the loop runs to the end and i is left at 3, which equals the array length. This is the classic not-found test. Real output:
3Question 4: call by value
#include <stdio.h> static void bump(int n) { n++; } int main(void) { int a[3] = {4, 8, 12}; bump(a[1]); bump(a[1]); printf("%d\n", a[1]); return 0; }Show answer
Both calls change only the local copy named n. The element a[1] stays at 8. Real output:
8
C Arrays Interview Questions, Part C: Challenges
Write these programs yourself and compile with -Wall -Wextra. Open the hint only if you are stuck for more than ten minutes.
Challenge 1: print the second largest element of an integer array. Make it work when the array contains duplicates of the largest value.
Show answer
Keep two variables,
firstandsecond. When you see a value larger than first, move first into second and store the new value in first. Otherwise, if the value is larger than second and different from first, update second. Decide what to print when no second largest exists.Challenge 2: rotate an array of N elements one position to the left, so {1, 2, 3, 4} becomes {2, 3, 4, 1}.
Show answer
Save a[0] in a temporary variable, shift every element one slot to the left with a loop that runs up to N – 2, then store the saved value in a[N – 1]. Test with N equal to 1 and 2.
Challenge 3: count how many elements are above the average of the array.
Show answer
Add the elements into a
longsum first. Compare each element times N with the sum to avoid integer division errors, or compute the average as adouble. Then loop a second time to count.Challenge 4: print a 16-bit value in binary with leading zeros, then count its set bits.
Show answer
Use a
uint16_tand a loop from bit 15 down to 0 with(v >> bit) & 1. Add that bit to a counter in the same loop.
C Arrays Interview Questions and Answers
These are the questions that interviewers for embedded and firmware roles ask again and again. Answer each one aloud in your own words before reading the model answer.
What is the difference between the contents of a local array and a static array at start?
Show answer
A local array lives on the stack and holds indeterminate values, so reading it before writing is a bug. A static or file-scope array lives in static storage and is set to zero before main() runs, which on a microcontroller is done by the startup code clearing .bss.
What does
int a[10] = {0};do?Show answer
It sets the first element to 0 explicitly, and every element without an initializer is set to zero, so the whole array is zeroed. It is not the same as
{5}, which sets only the first element to 5.Why can you not assign one array to another with
=?Show answer
An array is not a modifiable lvalue as a whole. You copy it element by element or with memcpy() using the byte count. An array placed inside a struct is copied when the struct is assigned.
How do you compute the number of elements in an array?
Show answer
Divide the size of the whole array by the size of one element:
sizeof arr / sizeof arr[0]. It works only where the real array type is visible. Inside a function that received the array as a parameter, sizeof gives the size of a pointer, so the length must be passed separately.How do you find the largest and smallest value in one pass, and why seed from the first element?
Show answer
Keep a running low and high, update them while scanning from index 1. Seeding from an actual element guarantees the starting value is in the data. Seeding with 0 fails for all-negative data, and seeding from a[0] requires the array to be non-empty.
How do you reverse an array in place and what is the cost?
Show answer
Use two indices from both ends, swap with a temporary variable and move them toward each other until they meet. It does N/2 swaps, takes linear time and needs constant extra memory. The middle element of an odd length array stays.
Why do you use an unsigned type when converting decimal to binary, and what is the special case?
Show answer
Unsigned arithmetic avoids sign and rounding surprises, and the loop condition works for every value. Zero needs a special case because the loop never runs for it, so the digit 0 must be stored before the loop.
Explain linear search and when you would not use it.
Show answer
It compares the target with each element in order and stops at the first match, so it works on unsorted data and costs up to N comparisons. For large sorted arrays that are searched often, binary search needs only about log2 N comparisons and is much better.
What is the difference between array index and position?
Show answer
Index counts from 0 and is what C uses. Position counts from 1 and is what people say. Position equals index plus one, so convert only when printing for humans.
What happens when you pass an array element to a function?
Show answer
C passes a copy of the value, so the function cannot change the original element. To let it modify the element, pass its address and use a pointer parameter.
What is an out-of-bounds array access and why is it dangerous on a microcontroller?
Show answer
It is reading or writing outside the declared elements. The behaviour is undefined: on an MCU a write may silently corrupt the neighbouring variable, the stack or a peripheral register, and a read may fault. Always keep indices below the length and validate lengths that come from outside the device.
Why are lookup tables declared
static constin firmware?Show answer
constdata is normally placed in flash, which saves RAM, and the compiler rejects accidental writes.statickeeps the name private to the file so it cannot collide with another file.
Common Mistakes Recap
| Topic | The classic mistake | The one-line fix |
|---|---|---|
| Initialization | Reading a local array before writing it | Initialize with = {0} |
| Copying | Using b = a | Loop or memcpy() |
| Max and min | Seeding with 0 | Seed from the first element |
| Reverse | Looping to N instead of N/2 | Stop when i < j fails |
| Binary | Forgetting zero and sign | Special-case zero, use unsigned |
| Search | Mixing index and position | Add 1 only when printing |
| Functions | Expecting a copy to change the original | Pass the address |
Study Tips, Best Practices and Safety
- Type every program yourself instead of pasting. Your fingers remember what your eyes skip.
- Change one number in a program and predict the new output before running it.
- Always compile with
-Wall -Wextraand treat each warning as a bug until proven otherwise. - Performance habit: prefer one pass over data and in-place algorithms, they save time and RAM on small devices.
- Security habit: every loop bound that comes from outside the device must be checked against the real array size.
Summary and Key Takeaways
- Know the four array states: garbage, zero, partially initialized and fully initialized. Interviewers love this one among C arrays interview questions.
- Single-pass algorithms, such as max and min, and in-place algorithms, such as reversing, are the embedded favourites.
- Binary conversion shows why the order of digits and array sizes matter.
- Linear search is simple and correct for small tables.
- Functions receive copies of array elements, and addresses when you want changes.
Conclusion
If you can answer these questions without looking, you have the array foundation required by embedded C programming and by most entry level firmware interviews. Keep practising with the challenges, and move on to passing whole arrays to functions in the next part of this free embedded C course. Share this page with a friend who is also preparing for placements: the course is free and always will be.
Topics Covered in This Free Embedded C Lecture
Frequently Asked Questions
What C array questions are asked in embedded interviews?
Common ones are array initialization and default values, the sizeof element count idiom, finding min and max, reversing in place, searching, out-of-bounds access, and what happens when an array is passed to a function.
How should I prepare for a C programming test on arrays?
Write each program by hand and compile it. Predict the output before running, and practise the common loop bounds so you never go off by one.
Is the output shown in the answers real?
Yes. Every program in the output prediction section was compiled with GCC and run, and the output is pasted exactly as printed.
Do I need an embedded board to practise these questions?
No. Every example here runs on a normal Linux, macOS or Windows laptop with GCC or Clang. A board is only needed later for hardware topics.
Why are the answers hidden in expandable sections?
Trying first and checking afterwards is the fastest way to learn. Open an answer only after you have written your own.
Where can I find more free embedded C practice?
Continue with the next lectures of the free C programming course on EmbeddedPathashala, where each chapter ends with a quiz and interview questions.
Keep Practising With the Free Embedded C Course
Finished the quiz? Retake it after two days, then continue to the next part of the chapter where we pass whole arrays to functions.
Need Help or More Information?
Questions about this free C programming course, embedded C training or career guidance? Get in touch.

2 Comments