How to change the actual argument passed to a function in C?

前端 未结 4 1806
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 13:15

I want to change the actual argument passed to a function and not a copy of it. For example:

char str[] = \"This is a string\";

I want to c

4条回答
  •  有刺的猬
    2020-12-22 13:43

    To change a string passed to a function in-place, use a regular pointer. For example:

    void lower_first_char(char *str)
    {
        *str = tolower(*str);
    }
    

    After this function executes, the first character of the passed string will be changed to lowercase.

提交回复
热议问题