0
0
Cprogramming~20 mins

Relational operators in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Relational Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of relational operators with integers
What is the output of the following C code?
C
#include <stdio.h>

int main() {
    int a = 5, b = 10;
    printf("%d\n", a < b);
    return 0;
}
A10
B0
C5
D1
Attempts:
2 left
💡 Hint
Remember that relational operators return 1 for true and 0 for false in C.
Predict Output
intermediate
2:00remaining
Relational operator with equal values
What will be the output of this C program?
C
#include <stdio.h>

int main() {
    int x = 7, y = 7;
    printf("%d\n", x >= y);
    return 0;
}
A1
BError
C0
D7
Attempts:
2 left
💡 Hint
Check if x is greater than or equal to y.
Predict Output
advanced
2:00remaining
Output of chained relational expressions
What is the output of this C code snippet?
C
#include <stdio.h>

int main() {
    int a = 3, b = 5, c = 7;
    printf("%d\n", a < b < c);
    return 0;
}
ASyntax Error
B1
C0
D3
Attempts:
2 left
💡 Hint
Remember how relational operators associate and the result of comparisons in C.
Predict Output
advanced
2:00remaining
Relational operator with pointers
What will be the output of this C program?
C
#include <stdio.h>

int main() {
    int arr[3] = {1, 2, 3};
    int *p1 = &arr[0];
    int *p2 = &arr[2];
    printf("%d\n", p1 > p2);
    return 0;
}
A0
B1
CUndefined behavior
DCompilation error
Attempts:
2 left
💡 Hint
Compare the memory addresses pointed by p1 and p2.
🧠 Conceptual
expert
3:00remaining
Behavior of relational operators with floating-point NaN
In C, what is the result of the expression (x < y) if x or y is NaN (Not a Number)?
AThe expression causes a runtime error
BThe expression evaluates to 1 (true)
CThe expression evaluates to 0 (false)
DThe expression causes a compilation error
Attempts:
2 left
💡 Hint
Think about how comparisons with NaN behave according to IEEE floating-point rules.