diff --git a/docs/day-11/pointers-in-cpp.md b/docs/day-11/pointers-in-cpp.md index 258adb8b..d0bbc62a 100644 --- a/docs/day-11/pointers-in-cpp.md +++ b/docs/day-11/pointers-in-cpp.md @@ -254,47 +254,4 @@ increment(p); ``` After the increment() function is called, the value of the variable x will be incremented to 6. -Here is an example of a complete program that passes a pointer to a function: - -```cpp -#include - -using namespace std; - -void increment(int *p) { - *p += 1; -} - -int main() { - int x = 5; - int *p = &x; - - increment(p); - - cout << x << endl; // Prints 6 - - return 0; -} -``` - -## How to Return a Pointer from a Function in C++? - -To return a pointer from a function in C++, you need to declare the return type of the function as a pointer to the type of data that you want to return. For example, if you want to return a pointer to an integer, you would declare the return type of the function as int*. - -Here is an example of a function that returns a pointer to an integer: - -```cpp -int* getIntPtr() { - int* pInt = new int(10); - return pInt; -} -``` - -This function allocates a new integer on the heap and returns a pointer to it. The caller of the function is then responsible for deleting the integer when it is no longer needed. -Here is an example of how to call the getIntPtr() function: - -```cpp -int* pInt = getIntPtr(); -cout << *pInt << endl; // Prints "10" -delete pInt; -``` +Here is an example of a complete program that passes a pointer to a function: \ No newline at end of file