当前位置: 动力学知识库 > 问答 > 编程问答 >

Passing a pointer in C

问题描述:

This question already has an answer here:

  • Segmentation fault of char * assignment [duplicate]

    4 answers

网友答案:

The string "t" is put into read only memory. For historical reasons you can use char *. Instead do

char g[] = "t";

This will create a read/write copy on the stack.

网友答案:

Because g is string literal and you are trying to modify it inside function helper

char *g = "t";  // <-- this is string literal

Change this to array syntax, and you're ok

char g[] = "t";
分享给朋友:
您可能感兴趣的文章:
随机阅读: