C के Operators
In this page:
result = operand1 operator operand2;
// operator: arithmetic (+ - * / %), relational (== != < >), logical (&& || !)
Operators क्या हैं?
एक operator एक special symbol है जो एक या ज़्यादा values पर, जिन्हें operands कहते हैं, एक operation perform करता है, एक नई value produce करते हुए -- उदाहरण के लिए, + symbol दो numeric operands को साथ add करता है।
उदाहरण: What are Operators?
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare sum and set it to 3 + 4
int sum = 3 + 4;
// Print formatted text to the screen
printf("%d", sum);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
C में Operators की Categories
C operators को इस आधार पर categories में बांटता है कि वे किस तरह का result produce करते हैं: arithmetic operators numbers compute करते हैं, relational operators values compare करते हैं, और logical operators truthy या falsy results combine करते हैं।
उदाहरण: Categories of Operators in C
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare sum and set it to 3 + 4
int sum = 3 + 4;
// Declare isGreater and set it to sum > 5
int isGreater = sum > 5;
int result = (sum > 5) && (sum < 10);
// Print formatted text to the screen
printf("%d %d %d", sum, isGreater, result);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Operators और Operands
हर operator operands पर काम करता है -- + और * जैसे ज़्यादातर operators binary हैं और उन्हें दो operands चाहिए, जबकि ++ और unary - जैसे कुछ unary हैं और सिर्फ एक single operand पर काम करते हैं।
उदाहरण: Operators and Operands
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
int a = 5, b = 3;
// Declare sum and set it to a + b
int sum = a + b;
// Declare neg and set it to -a
int neg = -a;
// Print formatted text to the screen
printf("%d %d", sum, neg);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Expressions में Operators Combine करना
अलग categories के operators अक्सर एक single expression में combine होते हैं, जैसे एक if statement के अंदर इस्तेमाल होने वाली एक condition बनाने के लिए arithmetic और relational operators मिलाना।
उदाहरण: Combining Operators in Expressions
// 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;
// Check whether score + 5 > 70
if (score + 5 > 70) {
// Print formatted text to the screen
printf("Passed");
}
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Operator Precedence का Preview
जब एक expression कई operators मिलाता है, C उन्हें एक fixed precedence order के हिसाब से evaluate करता है -- default से multiplication और division addition और subtraction से पहले चलते हैं, और parentheses हमेशा उस default order को override कर सकते हैं।
उदाहरण: Operator Precedence Preview
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare result and set it to 2 + 3 * 4
int result = 2 + 3 * 4;
// 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
=(assignment) को==(comparison) से confuse करना।- यह उम्मीद करना कि
7 / 23.5 देगा, जब integer division 3 देता है। - यह मान लेना कि
a + b * cleft to right evaluate होता है, जब*की precedence ज़्यादा है।
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: