Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions