← Back to C Course | Chapter 3: Operators | Lesson 1 of 9

C के Operators

Operators वे symbols हैं जो एक नई value produce करने के लिए एक या ज़्यादा operands पर काम करते हैं, और C इन्हें category में बांटता है -- arithmetic, relational, और logical -- वे जिस तरह का result produce करते हैं उसके आधार पर।
Syntax
c
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?

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;
	// Print formatted text to the screen
	printf("%d", sum);
	// Return 0 to signal that the program finished successfully
	return 0;
}

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

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;
}

Operators और Operands

हर operator operands पर काम करता है -- + और * जैसे ज़्यादातर operators binary हैं और उन्हें दो operands चाहिए, जबकि ++ और unary - जैसे कुछ unary हैं और सिर्फ एक single operand पर काम करते हैं।

उदाहरण: Operators and Operands

c
// 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;
}

Expressions में Operators Combine करना

अलग categories के operators अक्सर एक single expression में combine होते हैं, जैसे एक if statement के अंदर इस्तेमाल होने वाली एक condition बनाने के लिए arithmetic और relational operators मिलाना।

उदाहरण: Combining Operators in Expressions

c
// 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;
}

Operator Precedence का Preview

जब एक expression कई operators मिलाता है, C उन्हें एक fixed precedence order के हिसाब से evaluate करता है -- default से multiplication और division addition और subtraction से पहले चलते हैं, और parentheses हमेशा उस default order को override कर सकते हैं।

उदाहरण: Operator Precedence Preview

c
// 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;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. = (assignment) को == (comparison) से confuse करना।
  2. यह उम्मीद करना कि 7 / 2 3.5 देगा, जब integer division 3 देता है।
  3. यह मान लेना कि a + b * c left to right evaluate होता है, जब * की precedence ज़्यादा है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.