中級 › error: invalid operands to binary ==(構造体同士の==比較) › パターン2
error: invalid operands to binary ==(構造体同士の==比較)
構造体同士を==で比較しようとしたときに出るエラーです。
1 #include <stdio.h> 2 3 struct Color { int r, g, b; }; 4 5 int main(void) { 6 struct Color c1 = {255, 0, 0}; 7 struct Color c2 = {255, 0, 0}; 8 if (____________________________________________) { ^ 9 printf("same color\n"); 10 } 11 return 0; 12 }
main.c:8:12: error: invalid operands to binary == (have 'struct Color' and 'struct Color')
空欄を埋めてコンパイル・実行を通す
メンバが3つに増えても事情は同じです。構造体全体の比較演算子はCには存在しません。
次の問題