Question Bank (3 marks) · Q14
Q.Write a C program to illustrate the compact represention of arithmetic operations.
Karnataka PUCTextbookLong· 3mImportance★★★★★est
47% · 72/154 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →[!TLDR]
Compound assignment operators (+=, -=, *=, /=, %=) give a compact way of writing a = a op b.
C allows an arithmetic operator and the assignment operator to be combined into a single compound (shorthand) operator. Thus a += b means a = a + b, and similarly for -=, *=, /= and %=. The program demonstrates each on the same variable.
#include <stdio.h>
int main()
{
int a = 10, b = 3;
a += b; printf("a += b : a = %d\n", a); /* a = a + b */
a -= b; printf("a -= b : a = %d\n", a); /* a = a - b */
a *= b; printf("a *= b : a = %d\n", a); /* a = a * b */
a /= b; printf("a /= b : a = %d\n", a); /* a = a / b */
a %= b; printf("a %= b : a = %d\n", a); /* a = a % b */ …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.