中級 › error: invalid operands to binary ==(構造体同士の==比較) › パターン1
error: invalid operands to binary ==(構造体同士の==比較)
構造体同士を==で比較しようとしたときに出るエラーです。
1 #include <stdio.h> 2 3 struct Point { int x, y; }; 4 5 int main(void) { 6 struct Point a = {1, 2}; 7 struct Point b = {1, 2}; 8 if (______________________________) { ^ 9 printf("same\n"); 10 } 11 return 0; 12 }
main.c:8:11: error: invalid operands to binary == (have 'struct Point' and 'struct Point')
空欄を埋めてコンパイル・実行を通す
Cの==は組み込み型専用です。構造体を比較するには、メンバを1つずつ==で比較する必要があります。
次の問題