answersLogoWhite

0

#include <iostream>

#include <string>

std::string* concat_print_strings(std::string* pStr1, std::string* pStr2 )

{

std::string * strResult = new std::string( *pStr1 );

strResult->append( *pStr2 );

std::cout << strResult->c_str() << std::endl;

return( strResult ); }

int main()

{

std::string str1 = "This is a string.";

std::string str2 = " And this is another string.";

std::string* pStr = concat_print_strings( &str1, &str2 );

delete( pStr );

pStr = NULL;

return( 0 ); }

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is virtual function table?

A virtual function table is a table of pointers to functions.


What is scanF function?

scanf() is an input function which reads input from the standard input devices such as keyboard. Syntax: scanf("Control Character",address_list); where control character is a sequence of one or more character such as %d,%f,%lf,%lld. Address list specifies the variables, pointers etc. e.g. scanf("%d",&amp;num);


What is meant by passing function to another function in c plus plus?

Just as pointers can point to variables, pointers can also point to functions. Thus you can pass function pointers to functions. In so doing, you can alter the behaviour of the function by having it call dynamically call arbitrary functions rather than just preset functions.


Function prototype in c?

Yes. Examples can be found in stdio.h


Where are array of functions used?

Function Pointers are basically used when we want to select a function which is to be used dynamically at run time.


Character arrays using pointers notes?

i don't know ask someone else


Why you use pointers?

Because you can produce fast and efficient code. Function arguments are passed "by value", and so you can't change the original value of the argument, but if you use pointers, you can.


What are functions and pointers in c?

function-these are self contained block of statements to solve a particular task whereas pointers are defined as the variable which stores the address of another variable


Is Use of pointers in function saves the memory space?

No. But avoiding unnecessary duplication of data does.


How can you use pointers as function arguments?

Like any other value/variable -- nothing special.


Is it possibly to return an array of strings in a function without using pointers in C plus plus?

No.


When do you use pointers in C?

There are many uses of pointer in C. Pointers are efficient and elegant to use. All string variables are pointers, and calling a function using a pointer allows the function to change the value globally. These are what you can do with pointers in C. 1) Returning multiple values by passing address of variables. eg. foo(&amp;a,&amp;b,&amp;c); 2) When you want to modify the value passed to function. eg. scanf() function. int n; scanf("%d",&amp;n); /* pass address of variable n so that scanf can change its value*/ 3) When you need to pass large data structure to function, it is more efficient to pass pointer to structure than passing the entire structure. If you don't want to modify the structure members, you can use 'const' keyword which the ANSI-complaint C compiler will either warn or give error if you modify. eg strlen(const char *str) in string library should not modify the content of str. 4) Implementing 'goto' data structures are easy with pointers. eg. linked-list,binary trees, hash table. 5) You can allocate dynamic memory using pointers. 6) Pointers to function are used for call back function and jump table. eg qsort() and bsearch() functions require the caller to provide pointer to function to do the comparison.