TITLE: Pointer in C++
AIM: To write programs in c++ using pointers
THEORY: Pointers in C++ are variables that store memory addresses instead of values. They allow direct manipulation of memory, enabling dynamic memory allocation and efficient data handling. Through pointers, you can access and modify data at a specific memory location, aiding in tasks like passing data between functions, creating data structures like linked lists, and optimizing certain algorithms. However, incorrect usage of pointers can lead to memory leaks and segmentation faults, so careful management is crucial.
ALGORITHM:
1. Start
2. Declare a float variable named var1 and assign it the value 3.46.
3. Declare a pointer to float named floatPtr and initialize it with the address of var1.
4. Print the value of var1.
5. Print the value pointed to by floatPtr (i.e., *floatPtr).
6. Print the address of var1 using &var1.
7. Print the value stored in floatPtr.
8. Print the address of floatPtr using &floatPtr.
9. Declare an int variable named var2 and assign it the value 3.
10. Declare a pointer to int named intPtr and initialize it with the address of var2.
11. Print the value of var2.
12. Print the value pointed to by intPtr (i.e., *intPtr).
13. Print the address of var2 using &var2.
14. Print the value stored in intPtr.
15. Print the address of intPtr using &intPtr.
16. End
CONCLUSION: The program is executed using pointers by storing the values in the pointers and then initializing it in the program.