The Wayback Machine - https://web.archive.org/web/20210417195742/https://www.geeksforgeeks.org/results-of-comparison-operations-in-c-and-c/
Skip to content
Related Articles

Related Articles

Results of comparison operations in C and C++
  • Difficulty Level : Medium
  • Last Updated : 28 May, 2017
GeeksforGeeks - Summer Carnival Banner

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 \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.




#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 contributed by Rajat. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :