This project demonstrates how to use pointers for memory manipulation, dynamic memory allocation, and working with arrays in C++. It includes examples of:
- Pointer arithmetic
- Dynamic memory allocation (
new
anddelete
) - Array manipulation using pointers
The program is modularized for better understanding and serves as a learning resource for developers exploring C++ pointers and memory management.
- Initialize an array with user inputs using pointers.
- Display array values and their memory addresses.
- Demonstrates the use of
new
anddelete
to allocate and deallocate memory dynamically.
- Calculate the sum of elements in an array using pointer arithmetic.
- Functions like
initializeArray
,displayArray
, anddynamicMemoryExample
separate the logic for easier understanding.
- C++ Compiler (e.g.,
g++
for Linux/Ubuntu or MinGW for Windows). - Basic knowledge of C++ programming, particularly pointers and arrays.
git clone https://github.com/s-v7/Ponteiros_Em_C.git
cd Ponteiros_Em_C
g++ pointers.cpp -o output
./output
Enter a value for position [0]: 5
Enter a value for position [1]: 10
Enter a value for position [2]: 15
...
Address: 0x7ffee3a8b8d0 -> Value: 5
Address: 0x7ffee3a8b8d4 -> Value: 10
Address: 0x7ffee3a8b8d8 -> Value: 15
...
Sum of array elements: 150
Enter the size of the dynamic array: 5
Dynamic Array [0]: 0
Dynamic Array [1]: 2
Dynamic Array [2]: 4
Dynamic Array [3]: 6
Dynamic Array [4]: 8
Dynamic memory deallocated.
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
- Fork this repository.
- Create a new branch for your changes:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add feature description"
- Push to your branch:
git push origin feature-name
- Open a pull request.
This project is licensed under the MIT License.
For questions or suggestions, feel free to reach out:
- Author: Silas Vasconcelos Cruz
- GitHub: s-v7
pointers
arrays
C++
memory-management
educational