Tutorialspoint.dev

Results of comparison operations in C and C++

In C, data type of result of comparison operations is int. For example, see the following program.

#include<stdio.h>
int main()
{
    int x = 10, y = 10;
    printf("%d ", sizeof(x == y));
    printf("%d ", sizeof(x < y));
    return 0;
}

Output:

4
4

Whereas in C++, type of results of comparison operations is bool. For example, see the following program.

#include<iostream>
using namespace std;
  
int main()
{
    int x = 10, y = 10;
    cout << sizeof(x == y) << endl;
    cout << sizeof(x < y);
    return 0;
}

Output:

1
1


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter