Passing strings to functions in C involves sending the memory address of the first character of the string to the function rather than passing the entire string itself.
C does not have built-in string types, so strings are represented as arrays of characters, and passing the array's address allows functions to manipulate the original string.
Syntax:
Function Declaration:
void myFunction(char *str);
Function Definition:
void myFunction(char *str) {
// Function body
}
Function Call:
char myString[] = "Hello, World!";
myFunction(myString);
Strings in C are represented as arrays of characters, and their name is a pointer to the first character.
When passing a string to a function, use a pointer parameter to receive the memory address of the first character of the string.
The function can now access and modify the original string through the provided pointer.
Any changes made to the string within the function are reflected outside the function since the function operates on the original memory.
Passing by reference is more efficient than passing by value for large strings because it avoids copying the entire string.
Program.c
Output:
Original String: Hello, World
Modified String: Hello, World (modified)
Resources :
Featured
Special title treatment
With supporting text below as a natural lead-in to additional content.