結構初歩的な話ですが、自分用メモ。
個人的に、C→Javaは入りやすいイメージですがJava→Cはなんとも。。。
構造体はJavaのクラスのように、構造体の中で定義されたデータ型はメンバ変数のように扱うのです。
※ここではアロー演算子については触れません。
Javaソース
クラスHogeをインスタンス生成することで、Hogeクラスのint型変数の値を出力、書き換えができます。
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Hoge hoge = new Hoge();
System.out.println(hoge.num);
hoge.num = 6;
System.out.println(hoge.num);
}
}
class Hoge{
int num = 5;
}
C言語ソース
実体を持つ構造体に限るのでそこだけ注意です。
#include <stdio.h>
int main(void){
struct student{
int num;
};
struct student student_hoge;
student_hoge.num = 5;
printf("%d\n", student_hoge.num);
return 0;
}