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 Plus MyLab Programming with Pearson eText -- Access Card Package (9th Edition)
- Write a C++ function that uses pointer notation only to swap the contents of two integer arrays whose size is equal to SIZE?arrow_forwardWrite a program to swap two integers you should write a function named as swap_int and it should accept arguments as pointers then it should swap integers by dereferencing those pointers.arrow_forwardProgram in C. Suppose three numbers x, y, z are passed to a function. Implement this function to assign the values of y to x, z to y and x to z and return these three changed values to main. Use pointer.arrow_forward
- Write a program which will take pointer and display the number on screen. Take number from user and print it on screen using that function.arrow_forwardExplaining the importance of the concept of pointer, show how to obtain the address and value of a variable named deg that holds the value 5 in the int data type by using a pointer.arrow_forwardWrite a complete program. In the main function, do the following: Take two integer numbers from user input. Call a function to swap the two numbers using pointers.arrow_forward
- Write a C program to swap two integers you should write a function named as swap_intand it should accept arguments as pointers then it should swap integers bydereferencing those pointers.arrow_forwardIn 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_forwardProgram In C Create one function that contains only one for loop to print the passed array of pointer. So, lines from //A to //B need to be replaced with only two function calls: one function call to print months (from the month array), and the second function call for printing the days (form the day array). Both function calls are for the same function but with different parameters.arrow_forward
- Write a C++ program that asks for two lowercase characters. Pass the two entered characters, using pointers, to a function named capit(). The capit() function should capitalize the two letters and return the capitalized values to the calling function through its pointer arguments. The calling function should then display all four lettersarrow_forwardThe Task: Create a pointer to a function that takes an integer argument and returns an array of pointers to functions that accept a string argument and return an integer.Whew! You have to read the specification at least three times to realise you don't comprehend it.How do you handle such complication?arrow_forwardWrite a statement that declares a prototype for a function divide that takes four arguments and returns no value. The first two arguments are of type int. The last two arguments arguments are pointers to int that are set by the function to the quotient and remainder of dividing the first argument by the second argument. The function does not return a value.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