Skip to content
Solved Examples · Example 9

Q.​1) Write a C program to check whether given two integers are equal.
#include<stdio.h>  
void main()  
{  
    int x=4, y=4;  
    if(x==y)  
        printf("x and y are equal\n");  
}  

Karnataka PUCTextbookLong· 3mImportance★★★★★est
29% · 44/154 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

[!TLDR]

The == operator tests two integers for equality; when they match, the if statement executes and the message is printed.

Relational operators compare two operands and give a result that is true (non-zero, i.e. 1) or false (0). The equality operator == returns true only when both operands are equal. In the program x and y are both initialized to 4, so x==y is true (1) and the printf inside the if is executed. A complete standard version is:

#include <stdio.h>

int main(void)
{
    int x = 4, y = 4;
    if (x == y)
        printf("x and y are equal\n"); …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.