Kit Library / Computer Science / C Programming / Memory Management

⚡ Topic Learning Kit

C Arrays & Pointers

English 22 leveled MCQs Free

Shared by a Veda teacher · Generated with Veda AI

Veda Bites

The whole idea, one bite at a time

Veda Bites are swipeable micro-lessons — each one teaches exactly one idea. The bites below come from this kit — swipe through them in the app.

💡 Key Idea

Arrays and Pointers: The Dynamic Duo

Arrays and pointers work together in C.

In C, an array is a collection of elements of the same type stored in contiguous memory locations. A pointer stores the memory address of a variable. The array name itself acts as a pointer to the first element, making them closely related. Understanding this relationship is key to efficient C programming.

↳ Arrays and pointers are two sides of the same coin in C.

📖 Definition

1D Array Declaration and Initialization

Declare and initialize arrays easily.

A 1D array is declared with `type array_name[size];`. For example, `int marks[5];` creates an array of 5 integers. You can initialize at declaration: `int marks[5] = {90, 85, 78, 92, 88};`. If fewer values are given, the rest are zero-initialized.

↳ 1D arrays store a fixed-size sequence of elements of the same type.

📖 Definition

Multi-dimensional Arrays

Tables and matrices in C.

A multi-dimensional array is an array of arrays. For example, `int matrix[3][3];` creates a 3x3 matrix. It is stored in row-major order, meaning rows are stored contiguously. Access elements with `matrix[row][col]`.

↳ Multi-dimensional arrays are arrays of arrays, useful for matrices and tables.

💡 Key Idea

Variable Length Arrays (VLAs)

Arrays with size decided at runtime.

A Variable Length Array (VLA) allows the array size to be determined at runtime, not compile time. For example, `int n; scanf("%d", &n); int arr[n];`. This is useful when the size is not known in advance. However, VLAs have limitations: they cannot be initialized at declaration and may cause stack overflow if too l…

↳ VLAs provide flexibility but require careful memory management.

💡 Key Idea

Flexible Array Members

Arrays that adapt to structure size.

A flexible array member is the last member of a structure that can have an array of unspecified size. It allows the structure to have a variable-length array at the end. For example, `struct Student { int id; float marks[]; };`. The array size is determined when memory is allocated.

↳ Flexible array members enable structures with variable-size data.

💡 Key Idea

Advanced Control Flow: goto, NULL, Comma Operator

Control flow beyond loops and conditions.

The goto statement jumps to a labeled statement. The NULL statement is a semicolon alone, doing nothing. The comma operator evaluates multiple expressions, returning the last. These are advanced tools that can simplify code but also make it less readable.

↳ goto, NULL, and comma operator offer alternative control flow but should be used sparingly.

💡 Key Idea

setjmp and longjmp for Non-local Jumps

Jump out of deep function calls.

`setjmp` and `longjmp` are used for non-local jumps, allowing you to jump from a deeply nested function back to a saved point. `setjmp` saves the environment, and `longjmp` restores it. This is useful for error handling, but it bypasses normal function return and can cause resource leaks.

↳ setjmp/longjmp enable non-local jumps but require careful cleanup.

📖 Definition

Pointer Initialization and Dereferencing

Pointers store addresses, not values.

A pointer is declared with `type *ptr;`. Initialize it with the address of a variable using `&`. Dereference with `*` to access the value at the address. For example, `int x = 10; int *p = &x; printf("%d", *p);` prints 10.

↳ Pointers store addresses; dereferencing accesses the value.

📖 Definition

Special Pointer Types: NULL, Void, Wild, Dangling

Pointers have special states to know.

NULL pointer points to nothing (address 0). Void pointer (`void *`) can point to any type but must be cast before dereferencing. Wild pointer is uninitialized. Dangling pointer points to memory that has been freed. Avoid wild and dangling pointers.

↳ Know the special pointer types to avoid bugs.

💡 Key Idea

Double Pointers (Pointer to Pointer)

Pointers that point to pointers.

A double pointer stores the address of another pointer. Declared as `int pp;`. It is useful for modifying pointer values in functions and for 2D arrays. For example, `int x = 5; int *p = &x; int pp = &p;` then `**pp` gives 5.

↳ Double pointers allow indirect access and modification of pointers.

💡 Key Idea

Function Pointers and Pointers to Functions

Store and call functions via pointers.

A function pointer stores the address of a function. Declare as `return_type (*ptr)(parameters);`. Assign `ptr = function_name;` and call via `ptr(args);`. This enables callbacks and dynamic function selection.

↳ Function pointers allow functions to be passed as arguments.

💡 Key Idea

Multilevel Pointers

Pointers to pointers to pointers...

Multilevel pointers are pointers that point to other pointers. For example, `int ***p;` is a pointer to a pointer to a pointer. They are used in complex data structures and dynamic memory allocation. Each level adds another indirection.

↳ Multilevel pointers add layers of indirection, useful for complex structures.

🛠️ Application

Practical: Store and Analyze Marks

Use arrays and pointers for real data.

A common task is to store marks of N students using an array and use pointers to calculate average, highest, and lowest. This demonstrates array traversal with pointers.

↳ Pointers simplify array processing and analysis.

🛠️ Application

Practical: Matrix Operations with 2D Arrays

Perform matrix math using pointers.

Matrix addition, subtraction, and multiplication can be implemented using 2D arrays and pointer arithmetic. This is a classic application of multi-dimensional arrays.

↳ 2D arrays and pointers enable matrix computations.

🛠️ Application

Practical: Dynamic Memory with malloc()

Allocate memory at runtime.

Use `malloc()` to allocate memory dynamically. For example, store employee salaries and compute total and highest. This requires pointer arithmetic and careful memory management.

↳ Dynamic memory allocation allows flexible data storage.

🛠️ Application

Practical: Pointer to Pointer for Modifying Values

Modify variables through multiple levels.

Double pointers allow functions to modify the pointer itself. This is useful for linked lists and dynamic data structures.

↳ Double pointers enable modifying pointer values in functions.

⚠️ Common Mistake

Common Mistakes with Arrays and Pointers

Avoid these pitfalls.

↳ Be careful with memory and bounds to avoid crashes.

🎯 Exam Tip

Exam Tips for Arrays and Pointers

Score well with these tips.

↳ Practice pointer problems to ace exams.

🧠 Memory Trick

Memory Trick: Pointer to Array

Remember: array name is a pointer.

Think of an array name as a constant pointer to its first element. So `arr` is like `&arr[0]`. This helps remember that `arr[i]` is equivalent to `*(arr + i)`.

↳ Array indexing is just pointer arithmetic in disguise.

Smart notes

What you'll study, topic by topic

1

Arrays and Pointers in C: Core Concepts and Applications

8 min

This topic covers arrays (1D, multi-dimensional, VLAs, flexible array members) and pointers (initialization, dereferencing, special types, double pointers, function pointers, multilevel pointers) in C. It includes advanc…

  • Arrays store multiple elements of the same type in contiguous memory.
  • The array name acts as a pointer to the first element.
  • Multi-dimensional arrays are arrays of arrays, stored in row-major order.

Full explanation, worked examples & memory tricks in the app

Leveled MCQ practice

Try the smart MCQs from this kit

All 22 questions, laddered from warm-up to topper-level, each with its answer and the reasoning behind it.

Warm-up · 4 questions

Q1. What is a 1D array in C? How is it declared and initialized?

Beginner

Answers and explanations are in the Veda app.

Q2. How do you access elements of a 2D array in C? Provide the syntax.

Beginner

Answers and explanations are in the Veda app.

Q3. What is the purpose of the `goto` statement in C? Give a simple example.

Beginner

Answers and explanations are in the Veda app.

Q4. How do you declare a pointer in C? How do you initialize and dereference it?

Beginner

Answers and explanations are in the Veda app.

Building up · 11 questions

Q5. What is a Variable Length Array (VLA) in C? Give an example.

Intermediate

Answers and explanations are in the Veda app.

Q6. What is the NULL statement in C? When is it used?

Intermediate

Answers and explanations are in the Veda app.

Q7. Explain the comma operator in C with an example.

Intermediate

Answers and explanations are in the Veda app.

Q8. What is a NULL pointer? What happens if you dereference it?

Intermediate

Answers and explanations are in the Veda app.

Q9. What is a void pointer? How is it used?

Intermediate

Answers and explanations are in the Veda app.

Q10. What is a wild pointer? How can it be avoided?

Intermediate

Answers and explanations are in the Veda app.

Q11. What is a dangling pointer? Give an example of how it occurs.

Intermediate

Answers and explanations are in the Veda app.

Q12. What is a double pointer (pointer to pointer)? How is it declared?

Intermediate

Answers and explanations are in the Veda app.

Q13. What is a pointer to a function? How is it different from a function pointer?

Intermediate

Answers and explanations are in the Veda app.

Q14. Explain the concept of 1D and multi-dimensional arrays in C. How are they stored in memory? Write a C program to add two 2x2 matrices using 2D arrays.

Intermediate

Answers and explanations are in the Veda app.

Q15. Discuss the different special types of pointers in C: NULL pointer, void pointer, wild pointer, and dangling pointer. Explain with examples how each is created and how to avoid issues.

Intermediate

Answers and explanations are in the Veda app.

Topper level · 7 questions

Q16. What is a Flexible Array Member in a structure? How is it declared?

Advanced

Answers and explanations are in the Veda app.

Q17. What are `setjmp` and `longjmp` functions used for in C?

Advanced

Answers and explanations are in the Veda app.

Q18. What is a function pointer? How do you declare and use it?

Advanced

Answers and explanations are in the Veda app.

Q19. What are multilevel pointers? Provide an example.

Advanced

Answers and explanations are in the Veda app.

Q20. Explain the concept of double pointers and multilevel pointers in C. Write a program that uses a double pointer to modify the value of an integer variable.

Advanced

Answers and explanations are in the Veda app.

Q21. What are function pointers and pointers to functions? How are they declared, initialized, and used? Provide a program that uses a function pointer to call different arithmetic operations.

Advanced

Answers and explanations are in the Veda app.

Q22. Describe the advanced control flow mechanisms in C: `goto`, NULL statement, comma operator, and `setjmp`/`longjmp`. Explain their use cases and provide a small example for each.

Advanced

Answers and explanations are in the Veda app.

Study it properly — free, in the app

The full Veda Bites deck, complete notes, spaced-repetition flashcards, leveled MCQs, tests and games for this kit — plus Daily Facts and the Arena, every day.