0% found this document useful (0 votes)
2 views2 pages

Module 3 - Programming in C Notes - Pointer

Pointers in C are variables that hold the memory address of another variable instead of its value, declared with an asterisk before the name. They enable efficient memory access, dynamic memory management, and allow functions to modify variables outside their local scope. Pointers are essential for implementing data structures and work closely with arrays and strings for efficient data manipulation.

Uploaded by

nishu8904814690
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Module 3 - Programming in C Notes - Pointer

Pointers in C are variables that hold the memory address of another variable instead of its value, declared with an asterisk before the name. They enable efficient memory access, dynamic memory management, and allow functions to modify variables outside their local scope. Pointers are essential for implementing data structures and work closely with arrays and strings for efficient data manipulation.

Uploaded by

nishu8904814690
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module-3 Arrays and Strings- 1BEIT105

Module-3 Continued - Chapter -2 pointers

Q. What Are Pointers? Explain the concept of pointers in C in detail.


A pointer is defined as a variable that holds the address of a value rather than the value itself.

• A pointer is declared by specifying its data type and name, with an asterisk (*) before
the name.
Syntax: data_type *pointer_name;

For example:
int x = 10;
int *p = &x;
Here:
• x is an integer variable storing the value 10.
• p is a pointer to an integer (int*), storing the address of x.
• &x gives the memory address of x.
Thus, instead of storing data directly, pointers store where data is located in memory.

Why Pointers Are Important?


Pointers are a powerful feature of C for several reasons:
1. Efficient Memory Access
Pointers allow direct access to memory locations, enabling fast, low-level manipulation of data.
2. Dynamic Memory Management
Features like malloc(), calloc(), and free() rely entirely on pointers. They allow a program to
request memory during runtime.
3. Call by Reference
Pointers allow functions to modify variables outside their local scope by passing memory
addresses instead of copies of values.

1
Module-3 Arrays and Strings- 1BEIT105

4. Data Structures
Advanced structures such as linked lists, trees, stacks, queues, and graphs are implemented
using pointers.
5. Arrays and Strings
Pointers work closely with arrays and are often used to traverse and manipulate them
efficiently.

How Pointers Work in Memory?


Each variable is stored at a unique location in memory identified by an address. A pointer stores
this address.
For example, if x is stored at address 0x7ffeef:
x → 10
p → address of x (0x7ffeef)
When we use the dereference operator *p, we access the value stored at the address held by p,
which is 10.

You might also like