Code Fix

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

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

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

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

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

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

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