Open In App

Results of comparison operations in C and C++

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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

C




#include<stdio.h>
int main()
{
    int x = 10, y = 10;
    printf("%d \n", sizeof(x == y));
    printf("%d \n", 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. 

C++




#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

Last Updated : 19 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads