Question: So I've been playing around with C lately and have been trying to understand the intricacies of passing by value/reference and the ability to manipulate

So I've been playing around with C lately and have been trying to understand the intricacies of passing by value/reference and the ability to manipulate a passed-in variable inside a function. I've hit a road block, however, with the following:

void modifyCharArray(char *input) { //change input[0] to 'D' input[0] = 'D'; } int main() { char *a = "hello"; modifyCharArray(a); printf("hello --> %s ", a); } 

So the idea was to just modify a char array inside a function, and then print out said array after the modification completed. However, this fails, since all I'm doing is modifying the value of input that is passed in and not the actual memory address.

In short, is there any way I can take in a char *input into a function and modify its original memory address without using something like memcpy from string.h?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!