In this tutorial section we are going to study the most important concept regarding pointer in C programming language. i.e. The features and uses of pointer.
In previous tutorial we have learned what is ponters?.
Let us have the review of pointer syntax.
Syntax:
datatype *var_name;
*var_name is the name of pointer variable of a datatype.the data type can be a valid data type.
Use of Pointers in C programming.
In the given fig.
int a=10;
The integer variable a is declared and initialized to 10.
int *ptr=&a;
*ptr=20;
int *ptr=&a;
Here the address of variable a is assigned to ptr.
*ptr=20;
The value 20 is assigned to pointer variable *ptr.
the value of a becomes 20 .Because of the ptr is assigned address of variable a.The value 20 is actually stored at address of vriable a i.e 2000.
Let us study some of the uses and features of pointers in C Language.
Uses of Pointer in C
1. Pointers are used to pass arguments by reference
2. Pointers are used to return multiple values
3. Pointers are used to accessing array elements
4. Pointers are used to Manage memory dynamicaly.
used to dynamic memory allocation
5. Pointers are used to to implement complex data structures
6. Pointers are used to do develope system-level programming where memory addresses are useful.
Features of Pointers in C.
1.Memory Management: Memory is accessed and managed efficiently with the pointers. The pointers dynamicaly assigns and releases the memory. Hence the pointers can be used to allocate memory dynamically.
2. Use of pointers save memory space.
3. The program execution time with pointers is faster because data manipulation are performed with the address, that is, pointers use direct access to memory location.
4. Pointer are used to perform file operations reading,writting modify etc.
5. Pointers are used to implements data structures. They are used to represents single or multidimensional arrays.
6. Pointers are used to access An array, of any type without use of its subscript range.
7. Pointers allocates memory dynamically.
Drawbacks of Pointers in C.
• Pointers read wrong value if pointers points to some incorect address or location.
• Erroneous input always leads to an erroneous output.
• if not pointers initialized the Segmentation fault can occurs..
• It requires one additional dereferences step.
• If programmer forgot to deallocate a memory then it will lead to a memory leak problem.
Previous Topic:-->> Syntax of Pointer initialization in C. || Next topic:-->>The Pointer to an array in C.
Other Topics:
Variables and Identifiers
Relational Operators
if-else statements
Switch case
While Loop
Infinite while Loops
C FOR Loop
Infinite for Loops
Continue in Loops
One Dimensional Array
Two Dimensional Arrays
Read and Display 2D Arrays
Types of functions
Passing Array To Functions
Nesting of Function
Array vs Structure
Array of Structure
Structures and Functions
Structures Within Structures
Use Of Pointers In C
File Handling In C
Loops FAQ
Arrays FAQ
count vowels in a file
Function FAQ
Conditional Statements Assignments
For Loops Assignments
Arrays Assignments
Function Assignments
Structure Assignments
Pointers Assignments
Files Assignments
Storage classes Assignments
Binary Files
count words,lines in a file
Copy files
Update File
Continue in Loops
break in Loops
Difference Between While and Do while
difference while do..while & for
malloc
calloc
Storage Classes
Operators MCQ
Conditional Statements MCQ
Loops MCQ
Arrays MCQ
Function MCQ
Structure MCQ
Pointers MCQ
Files MCQ
Storage classes MCQ