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

C के Arithmetic Operators

Arithmetic operators एक calculator के math buttons हैं: plus, minus, times, divide, और remainder। C इन्हें numbers से calculate करने के लिए इस्तेमाल करता है।
Syntax
c
result = operand1 + operand2;  // also - * / %

Addition (+) और Subtraction (-)

+ और - operators numeric values पर ordinary addition और subtraction perform करते हैं, int, float, या double operands के लिए same तरह काम करते हुए, बड़े expressions के अंदर precedence के standard mathematical rules follow करते हुए।

उदाहरण: Addition (+) and Subtraction (-)

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	int a = 10, b = 3;
	// Print formatted text to the screen
	printf("%d %d", a + b, a - b);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Multiplication (*) और Division (/)

* operator दो values multiply करता है, और / उन्हें divide करता है -- लेकिन C में दो integers divide करना integer division perform करता है, चुपचाप किसी भी fractional remainder को discard करते हुए, जो decimal result की उम्मीद करने वाले कई beginners को surprise करता है।

उदाहरण: Multiplication () and Division (/)

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	int a = 7, b = 2;
	// Print formatted text to the screen
	printf("%d %d", a * b, a / b);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Modulo Operator (%)

% integer division के बाद बचा हुआ सिर्फ remainder return करता है, इसे यह test करने का standard तरीका बनाते हुए कि एक number even है या odd (n % 2 == 0 check करके) या एक limit तक पहुँचने के बाद एक counter को वापस zero पर wrap करने का।

उदाहरण: Modulo Operator (%)

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare n and set it to 7
	int n = 7;
	// Print formatted text to the screen
	printf("%d", n % 2);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Increment Operator (++)

++ एक variable की value को exactly 1 बढ़ाता है। variable से पहले लिखा (++x) यह increase को आस-पास के expression में variable इस्तेमाल होने से पहले apply करता है; बाद में लिखा (x++) यह increase बाद में apply करता है।

उदाहरण: Increment Operator (++)

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare x and set it to 5
	int x = 5;
	// Print formatted text to the screen
	printf("%d %d", ++x, x++);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Decrement Operator (--)

-- एक variable की value को exactly 1 घटाता है, ++ जैसे same prefix/postfix timing rules follow करते हुए -- prefix एक expression में value इस्तेमाल होने से पहले decrement करता है, postfix तुरंत बाद।

उदाहरण: Decrement Operator (--)

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare x and set it to 5
	int x = 5;
	// Print formatted text to the screen
	printf("%d %d", --x, x--);
	// 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. 7 / 2 जैसे दो ints divide करना और 3.5 की उम्मीद करना, जब result 3 है।
  2. floating-point numbers के साथ % इस्तेमाल करना, जो compile नहीं होता; math.h से fmod इस्तेमाल करें।
  3. zero से divide करना, जो undefined behavior है।

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.