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?

自分用C言語学習 ~配列~

Posted at

配列

同じ型のデータをまとめて保存できる箱(変数の集まり)

配列の宣言

main.c
// フォーマット
型名 配列名[要素数];

// 例
int scores[3];

配列に値を入れる

main.c
int main() {

    int scores[3];

    // 値を入れる
    scores[0] = 80;
    scores[1] = 90;
    scores[2] = 70;

    .
    .
    .

    return 0;
}

javaとCとで異なる点

・配列の宣言
・配列の長さを知る方法

main.java
// 配列の宣言
int a[] = new int[];

// 配列の長さを知る方法(配列変数.lengthで簡単に取れる)
a.length
main.c
// 配列の宣言
int a[];

// 配列の長さを知る方法はない

添え字

main.c
d[0]
d[1]
d[2]

// この時の0, 1, 2が添え字

多次元配列

main.c
int a[3][4];

// 前の添え字が縦の範囲を表す
// 横の添え字が横の範囲を表す
0
0
6

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?