Key CPDS internal 1
Key CPDS internal 1
A pointer is a variable that stores the memory address of another variable. It "points to"
the location in memory where the variable is stored.
Declaring a Pointer Variable
To declare a pointer variable, use the asterisk symbol (*) before the pointer name.
data_type *pointer_name;
- data_type: Type of data the pointer will point to (e.g., int, char, float).
- pointer_name: Name of the pointer variable.
7.What is a file?
A file is a collection of related data or information stored on a computer's storage
device, such as a hard drive, solid-state drive, or flash drive. Files can contain various
types of data, including:
Text (documents, notes)
Images (photos, graphics)
Audio (music, voice recordings)
Video (movies, clips)
Executable programs (software, apps)
Binary data (compiled code, databases)
8.How addresses are assigned to pointers?
Addresses are assigned to pointers through various methods:
1. Address-of Operator (&): Gets the memory address of a variable.
int x = 10;
int *ptr = &x;
1. Dynamic Memory Allocation: Allocates memory at runtime using functions like
malloc(), calloc(), or realloc().
int *ptr = (int*) malloc(sizeof(int));
1. Array Indexing: Arrays store elements contiguously in memory; pointers can point to
array elements.
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr; // ptr points to arr[0]
1. Pointer Arithmetic: Incrementing/decrementing pointers moves them through
memory.