8 Pointers And Dynamic Memory

C Programming · Unit 8

Pointers and Dynamic Memory

Exam-focused notes for Pointers and Dynamic Memory (C Programming, BIT102): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.

What this unit covers

  • Pointer concept and declaration
  • Pointer arithmetic
  • Double pointers
  • Null pointers
  • Similarity between arrays and pointers
  • Pointers as function arguments
  • Dynamic memory allocation
  • Sizeof in DMA
  • Finding smallest element using pointers

Similarity between arrays and pointers

208110 marks

What is pointer? How it differs from array?Write a program to add two 2D matrices.[4+6]

--- A pointer is a variable that stores the memory address of another variable rather than storing a data value directly. Declaration syntax: Example: - & operator gives the address of a variable - operator dereferences a pointer (accesses value at that add...

Full solved answer →
20805 marks

What is pointer? Explain the similarity between array and pointer in brief. [5]

A pointer is a variable that stores the memory address of another variable rather than storing a direct value. It "points to" the location in memory where data is stored. Syntax: Example: Here, &a gives the address of a, and p (dereferencing) gives the valu...

Full solved answer →
20795 marks

Why array and pointer is similar? Write a program to show the similarity between an array and pointer. [5]

In C, arrays and pointers are closely related because: 1. Array name is a pointer: The name of an array acts as a constant pointer to the first element (base address) of the array. 2. Same memory access: Both arrays and pointers can be used to access memory...

Full solved answer →

Dynamic memory allocation

20805 marks

What is DMA? Write a program to read N numbers and find largest and smallest number using DMA. [5]

Dynamic Memory Allocation (DMA) is the process of allocating memory to a program at runtime (during execution) rather than at compile time. It allows a program to request memory as needed and release it when no longer required. In C, DMA is performed using ...

Full solved answer →

Finding smallest element using pointers

20785 marks

Write a program to find smallest element of an array using a pointer. [5]

--- --- Concept Description ------ ptr = arr Pointer assigned the base address of the array ptr Dereferences pointer to get the value at that address ptr++ Moves pointer to the next array element (next memory location) smallest Stores the minimum value foun...

Full solved answer →

Double pointers

20775 marks

What is pointer? Illustrate the use of a double pointer with suitable example. [5]

A pointer is a variable that stores the memory address of another variable rather than storing a direct value. Syntax: Example: - &x gives the address of variable x - p gives the value at the address stored in p (dereferencing) --- A double pointer is a poi...

Full solved answer →

Pointer concept and declaration

05 marks

Describe the concept of pointer and its arithmetic with suitable examples. [5]

A pointer is a variable that stores the memory address of another variable rather than storing a data value directly. Declaration Syntax: Example: - &x gives the address of variable x - ptr gives the value at the address stored in ptr (dereferencing) --- Op...

Full solved answer →