Explanation of Solution
Returning a pointer from the function:
Pointers can be returned from the function only if the reference pointer variable that points exists in the function.
Circumstance for successful return of a pointer:
The circumstances for returning pointer successful are listed below:
- When a pointer is passed as an argument in a function that is called.
- When a pointer variable is defined locally within the function there may be possibility for the contents of the variables being destructed after execution of the function. This can cause unexpected results.
- When pointer gets chunk of memory allocated dynamically.
- When a variable is allocated dynamically, the contents will be available until the compiler executes the delete operation.
Example:
// Include the necessary headers
#include <iostream>
using namespace std;
//function prototype to get alphabets
char *getalphabets();
//function prototype to display the array elements
void disparray(char[], int);
//main method
int main()
{
//variable declaration
const int SIZE = 3;
// get alphabets from the user
char *chkname = getalphabets();
//displays the content of array
cout << "The alphabets you entered...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
- Under what circumstances can you successfully return a pointer from a function?arrow_forwardHow to call function using pointer. Please Explain with Code Example?arrow_forwardIn C++, When an array is passed to a function as a pointer, the function doesn't know the size of the array. List 3 ways to handle this problem.arrow_forward
- Programming in C. Pointers The purpose of this program is to get familiar with pointers. Swaps Create and use a function that swaps two integers. Ask the user for the values. Display the swapped values. Create another function that swaps two doubles. Ask the user for the values. Display the swapped values. Create yet another function that swaps two strings. Ask the user for the strings Display the swapped values.arrow_forwardExplain the Pointers and Function Return Values with example.arrow_forwardCreate a function that can accept a pointers and array with values of 1000, 2, 3, 17, 50. Your program will display the array values and its averagearrow_forward
- In C programming: Write a function printAllCourses() which receives an array of course pointers and the array’s size, then prints all courses in the array by calling printCourseRow()arrow_forwardIn C Programming: Write a function inputAllCourses() which receives an array of course pointers and the array’s size, then allows the user to input all courses in the array by calling inputCourse()arrow_forwardCreate an array of four function pointers. Each pointer should point to a different function. Each of these functions should receive two integers and return a float. Using a loop call each of these functions using the addresses present in the array.arrow_forward
- Note: Write programs in c language format use in programs (Printf & Scanf)arrow_forwardUsing C++ Language Write a function call with arguments tensPlace, onesPlace, and userInt. Be sure to pass the first two arguments as pointers. Sample output for the given program: tensPlace = 4, onesPlace = 1 Code: #include <stdio.h> void SplitIntoTensOnes(int* tensDigit, int* onesDigit, int DecVal){ *tensDigit = (DecVal / 10) % 10; *onesDigit = DecVal % 10;} int main(void) { int tensPlace; int onesPlace; int userInt; scanf("%d", &userInt); /* Your solution goes here */ printf("tensPlace = %d, onesPlace = %d\n", tensPlace, onesPlace); return 0;}arrow_forwardin c++ Create a function that takes in a size and creates an array in the function of that size. The array should only contain even numbers. Return the array to main and show how that is done.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning