ADVERTISEMENT
ADVERTISEMENT

Get String value from function using Call by Reference.


IncludeHelp 21 June 2016

In this code snippet we will learn how to get string value from function using call by reference, in this code we will pass a string buffer and get value from the function.

C Code Snippet - Get String Value from function using Call by Reference

#include <stdio.h>
#include <string.h>

void getString(char *buffer){
    strcpy(buffer,"String from the function getString.");
}

int main()
{
    
    char mainBuffer[100];
    
    //pass mainBuffer to fill through function
    getString(mainBuffer);
    
    printf("Value of mainBuffer is: %s\n",mainBuffer);

    return 0;
}
    
    Value of mainBuffer is: String from the function getString. 

ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.