Uploaded by routineofnepalfinance

Pointer

advertisement
Pointer
Pointers are special variables in C language that hold memory addresses of other
variables. They act as direct references to memory locations, allowing you to
manipulate data indirectly and efficiently. Think of them as signposts pointing to
where values are stored in the computer's memory
Syntax: Data_Type * Variable_Name
Example: int *ptr; char *name;
The address-of operator (&) is used to obtain the memory address of a variable,
which can then be assigned to a pointer. For instance, ptr = &x; assigns the address
of variable x to the pointer ptr.
To access the value stored at the memory location pointed to by a pointer, you use
the dereference operator (*). For example, *ptr would retrieve the value stored at the
address held by ptr.
Pointers are used in C programming, due to enabling a wide range of tasks such as:
 Dynamic memory allocation: Creating and managing memory blocks at
runtime .
 Passing arguments by reference to functions: Allowing functions to modify
the original variables passed to them.
 Working with arrays: Array names act as pointers to their first elements, and
pointer arithmetic can be used to access and manipulate array elements.
Example: Wap in c to dispaly the value and memory address of
pointer.
Download