C के Arithmetic Operators
In this page:
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 (-)
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Multiplication (*) और Division (/)
* operator दो values multiply करता है, और / उन्हें divide करता है -- लेकिन C में दो integers divide करना integer division perform करता है, चुपचाप किसी भी fractional remainder को discard करते हुए, जो decimal result की उम्मीद करने वाले कई beginners को surprise करता है।
उदाहरण: Multiplication () and Division (/)
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Modulo Operator (%)
% integer division के बाद बचा हुआ सिर्फ remainder return करता है, इसे यह test करने का standard तरीका बनाते हुए कि एक number even है या odd (n % 2 == 0 check करके) या एक limit तक पहुँचने के बाद एक counter को वापस zero पर wrap करने का।
उदाहरण: Modulo Operator (%)
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Increment Operator (++)
++ एक variable की value को exactly 1 बढ़ाता है। variable से पहले लिखा (++x) यह increase को आस-पास के expression में variable इस्तेमाल होने से पहले apply करता है; बाद में लिखा (x++) यह increase बाद में apply करता है।
उदाहरण: Increment Operator (++)
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Decrement Operator (--)
-- एक variable की value को exactly 1 घटाता है, ++ जैसे same prefix/postfix timing rules follow करते हुए -- prefix एक expression में value इस्तेमाल होने से पहले decrement करता है, postfix तुरंत बाद।
उदाहरण: Decrement Operator (--)
// 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;
}
Login to try C/C++/Java/PHP code in the editor
7 / 2जैसे दो ints divide करना और 3.5 की उम्मीद करना, जब result 3 है।- floating-point numbers के साथ
%इस्तेमाल करना, जो compile नहीं होता;math.hसेfmodइस्तेमाल करें। - zero से divide करना, जो undefined behavior है।
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: