Code Fix

中級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')

空欄を埋めてコンパイル・実行を通す

広告
広告スロット(未設定)

error: invalid operands to binary ==(構造体同士の==比較)

Cの==は組み込み型専用で、構造体には定義されていません。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)