LoginSignup
3
3

More than 5 years have passed since last update.

C言語での関数の引数の配列はポインタ渡しである

Posted at

久しぶりにやったらド忘れしていたのでメモ。

void func(int a[],int n){
    //process
}

しばしば関数の引数に配列と要素数を渡す関数がある。
このaは配列そのものではなく、配列の先頭要素へのポインタである。
そのため、関数側で要素数を調べることができないので、要素数も渡している。

※aがもし配列そのものなら

int n = sizeof(a)/sizeof(a[0])

で取得できるはずだが、関数の引数にはポインタとして渡ってきているので、この方法は使えない

3
3
0

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
3
3