LearnFrenzy
Sign in Take a free test

C Programming · Topic 8 of 23

Arrays

  • 4 exercises
  • 40 questions
  • ~60 min
  • Answers explained

Interview Questions

Arrays · Study material

C Arrays Interview Questions and Answers

1. What is an array, and how is it stored?

A fixed number of elements of one type in one contiguous block of memory. Element i is at base + i × sizeof(element), which makes indexing O(1).

2. What is array decay?

In most expressions an array is converted to a pointer to its first element. It does not happen for sizeof a, &a or a string literal initialising a char array.

3. What is the difference between a, &a[0] and &a?

All hold the same address. a (after decay) and &a[0] are int *; &a is a pointer to the whole array, int (*)[N], so &a + 1 skips the entire array.

4. Why can't you find an array's length inside a function?

The function receives only a pointer, so sizeof measures the pointer. Pass the length as a parameter.

5. Can you assign one array to another?

No, an array is not a modifiable lvalue. Copy element by element or with memcpy(). An array inside a struct, however, is copied when the struct is assigned.

6. What are designated initializers?

A C99 feature that sets chosen elements by index: int a[10] = {[3] = 1, [7] = 2};. Elements not named are 0.

7. What is a variable length array, and when should you avoid it?

An array whose size is decided at run time, stored on the stack. Avoid it for large or untrusted sizes, since a big VLA can overflow the stack; use malloc() instead. VLAs are optional since C11.

8. How is a 2D array laid out in memory?

Row-major: all of row 0, then row 1, and so on. That is why functions must know the column count: void f(int m[][COLS]).

9. What happens if you access a[10] in a 10-element array?

Undefined behaviour. C does no bounds checking; the program may read garbage, corrupt other variables or crash.

10. Is i[a] valid?

Yes. a[i] is defined as *(a + i) and addition commutes, so i[a] is *(i + a) – legal, though never good style.

11. What does int a[static 10] in a parameter mean?

The caller promises to pass a non-null pointer to at least 10 elements. Compilers can warn when you pass less and may optimise using the promise.

12. What does C23 change for arrays?

The empty initializer = {} zeroes an array (even a VLA), constexpr constants can size arrays, and typeof copies an array's type.

Ready to test your Programming?

Timed online tests with instant scores and explanations.

About this section

About C Programming

C programming is the language most computer science courses start with and the foundation of operating systems, embedded devices and compilers. This section helps you learn C properly – data types, operators, control statements, functions, arrays, strings, pointers, structures, memory allocation and files – and then prove it with hundreds of practice questions explained line by line.

Why it matters

  • C teaches how a computer really works: memory, addresses and how data is stored
  • Pointers and memory questions are a favourite in written tests and technical interviews
  • Once you know C, learning C++, Java and Python becomes much easier
  • Embedded systems, operating systems and many companies' coding rounds still use C

Who it is for

  • School students (Class 11–12 computer science) building a strong programming base
  • College students (B.Tech, BCA, MCA, B.Sc CS) preparing for semester exams, lab work and viva
  • Freshers preparing for campus placements, aptitude-cum-coding tests and technical interviews
  • Anyone preparing for GATE CS or government IT exams

What every topic gives you

  • Study material in five tabs: concepts with runnable examples, coding techniques, programs, interview questions and a cheat sheet
  • MCQs that check your understanding of every concept
  • "Predict the output" puzzles – the trickiest part of written tests
  • "Find the error" programs that train you to spot bugs quickly
  • Complete programs with solutions and real output, verified on a compiler

Asked in

  • Campus placements
  • TCS, Infosys, Wipro tests
  • Technical interviews
  • GATE CS
  • University exams
  • Government IT exams

How to use this section

  1. Read the study material of a topic and run the examples yourself.
  2. Practise the four exercises – MCQs, output, errors, programs – and read every explanation.
  3. Test yourself with the timed online test, then revise the topics you got wrong.

Search LearnFrenzy

Esc

Quick links