9 Pointers

C Programming · Unit 9 · 6 hrs

Pointers

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

What this unit covers

  • Introduction
  • The & and * operator
  • Declaration of pointer
  • Chain of Pointers
  • Pointer Arithmetic
  • Pointers and Arrays
  • Pointers and Character Strings
  • Array of Pointers
  • Pointers as Function Arguments
  • Function Returning pointers
  • Pointers and Structures
  • Dynamic Memory Allocation

Pointers and Arrays

208010 marks

Explain the relation to array and pointer.Differentiate between call by value and call by reference with a suitable program.[2+8]

--- (a) Relation Between Array and Pointer In C, there is a strong relationship between arrays and pointers. Any operation that can be achieved by array subscripting can also be done with pointers. - An array name is itself an address (a constant pointer to...

Full solved answer →
20745 marks

Define pointer. Discuss the relationship between pointer and one-dimensional array. [1.5+3.5]

--- A pointer is a variable that stores the memory address of another variable. Instead of holding a data value directly, a pointer holds the address where that data is stored in memory. Syntax: Example: Here, ptr is a pointer to an integer. The operator & ...

Full solved answer →

Dynamic Memory Allocation

20805 marks

What is dynamic memory allocation? Explain with a suitable program. [5]

The process of allocating memory at the time of execution (runtime) is called dynamic memory allocation. Unlike static memory allocation where the size is fixed at compile time, dynamic memory allocation allows a program to request and release memory as nee...

Full solved answer →
20785 marks

Explain dynamic memory allocation with example. [5]

The process of allocating memory at the time of execution (runtime) is called dynamic memory allocation. Unlike static memory allocation where the size is fixed at compile time, dynamic memory allocation allows a program to request and release memory as nee...

Full solved answer →
20755 marks

What is dynamic memory allocation? Discuss the use of malloc() in dynamic memory allocation with example. [1+4]

--- (a) What is Dynamic Memory Allocation? Dynamic memory allocation is the process of allocating memory to a program at the time of execution (runtime) rather than at compile time. In static memory allocation, the size of memory (e.g., an array) is fixed a...

Full solved answer →

Pointers as Function Arguments

20795 marks

List any one advantage and disadvantage of the pointer. How do you pass pointers as function arguments? [5]

Returning more than one value from a function: A pointer allows a called function to directly modify the original variable in the calling function. This means a single function call can effectively return multiple modified values, which is not possible with...

Full solved answer →

Function Returning pointers

20771 marks

Define pointer. How do you return pointers from functions? Explain with example. [1]

A pointer is a variable that stores the memory address of another variable. Instead of holding a data value directly, it holds the location (address) where the data is stored in memory. Syntax: Example: int p; declares p as a pointer to an integer. --- A fu...

Full solved answer →