C के Relational Operators
In this page:
result = value1 == value2; // also != > < >= <=
Equal (==) और Not Equal (!=)
== test करता है कि दो values equal हैं या नहीं और != test करता है कि वे अलग हैं या नहीं; दोनों true के लिए 1 या false के लिए 0 produce करते हैं, और == को single = assignment operator से मिलाना सबसे common C bugs में से एक है।
उदाहरण: Equal (==) and Not Equal (!=)
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
int a = 5, b = 5;
// Print formatted text to the screen
printf("%d %d", a == b, a != b);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Greater Than (>) और Greater Than or Equal (>=)
> और >= test करते हैं कि left operand right operand से strictly greater है, या greater than or equal है -- आमतौर पर upper bounds check करने के लिए इस्तेमाल होता है, जैसे कि क्या कोई score एक passing threshold से ज़्यादा है।
उदाहरण: Greater Than (>) and Greater Than or Equal (>=)
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare score and set it to 75
int score = 75;
// Print formatted text to the screen
printf("%d %d", score > 70, score >= 75);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Less Than (<) और Less Than or Equal (<=)
< और <= test करते हैं कि left operand right operand से strictly less है, या less than or equal है -- > और >= की mirror image, अक्सर इनके साथ pair होकर यह check करने के लिए कि कोई value एक range के अंदर आती है या नहीं।
उदाहरण: Less Than (<) and Less Than or Equal (<=)
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare age and set it to 15
int age = 15;
// Print formatted text to the screen
printf("%d %d", age < 18, age <= 15);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Relational Outputs को समझना
C के original standard में कोई dedicated boolean type नहीं है -- relational और logical expressions बस integer 1 (true के लिए) या 0 (false के लिए) में evaluate होते हैं, यही कारण है कि आप उनके results सीधे arithmetic में या एक if condition की तरह इस्तेमाल कर सकते हैं।
उदाहरण: Understanding Relational Outputs
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare result and set it to (5 > 3)
int result = (5 > 3);
// Print formatted text to the screen
printf("%d", result);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Conditional Expressions
Relational operators ही conditional logic को possible बनाते हैं -- एक C program में हर if statement, while loop condition, और validation check आखिरकार इनमें से किसी एक operator के एक true/false result produce करने पर depend करता है।
उदाहरण: Conditional Expressions
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare age and set it to 20
int age = 20;
// Check whether age >= 18
if (age >= 18) {
// Print formatted text to the screen
printf("Adult");
}
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
a == bकी बजायif (a = b)लिखना, जो compare करने की बजाय assign करता है।1 < x < 10जैसे comparisons को chain करना, जो हमेशा true है।- floating-point values को
==से compare करना, जहाँ rounding errors surprising results cause करती हैं।
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: