0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

関数の引数(配列)の使い方が不明

Last updated at Posted at 2020-04-13

#配列の引数について
最近C言語を初めた初心者です。
質問です。
#質問
関数testではch_nameのアドレスを受け渡しています。
そのアドレスに"yonyon"を代入しますが、関数か抜けるとそれが維持されない理由がわかりません。

#include <stdio.h>

int test(char *pointer){  
    printf("pointer s = %s\n",pointer);
    pointer = "yyoonn";
    printf("pointer にyyoonnを代入する。\n");
    printf("pointer s = %s\n",pointer);
    return 0;
}
int main(void){
    char    ch_name[] = "yonyon";
    printf("ch_name s = %s\n",ch_name);
    test(ch_name);
    printf("ch_name s = %s\n",ch_name); 
}

####出力結果
ch_name s = yonyon
pointer s = yonyon
pointer にyyoonnを代入する。
pointer s = yyoonn
ch_name s = yonyon

最後なぜyonyonに戻ってしまうのかがわかりません。
どなたか教えてください。

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?