Having a function change the value a pointer represents in C

后端 未结 6 1255
攒了一身酷
攒了一身酷 2020-12-06 01:16

I have a main function that has a char, I am attempting to pass a pointer to that char into a function and have it change it from A to

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 01:25

    What you want is *charToChange = 'b';. The pointer charToChange is a local variable (parameter) in setChar, but you can change what it points to using the prefix * operator and an assignment. Note that *charToChange is a character, too, not a string.

提交回复
热议问题