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!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.