0% found this document useful (0 votes)
7 views2 pages

C Program for All Operators Explained

The document contains a C program that demonstrates the use of various operators including arithmetic, relational, logical, bitwise, assignment, increment/decrement, and the conditional (ternary) operator. It initializes two integers, a and b, and performs operations on them while printing the results. The program serves as a comprehensive example of operator functionality in C programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

C Program for All Operators Explained

The document contains a C program that demonstrates the use of various operators including arithmetic, relational, logical, bitwise, assignment, increment/decrement, and the conditional (ternary) operator. It initializes two integers, a and b, and performs operations on them while printing the results. The program serves as a comprehensive example of operator functionality in C programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program 1: Write a C program to perform all operators.

#include <stdio.h>
void main() {
int a = 10, b = 5;

printf("---- Arithmetic Operators ----\n");


printf("a + b = %d\n", a + b);
printf("a - b = %d\n", a - b);
printf("a * b = %d\n", a * b);
printf("a / b = %d\n", a / b);
printf("a %% b = %d\n", a % b);

printf("\n---- Relational Operators ----\n");


printf("a > b : %d\n", a > b);
printf("a < b : %d\n", a < b);
printf("a >= b : %d\n", a >= b);
printf("a <= b : %d\n", a <= b);
printf("a == b : %d\n", a == b);
printf("a != b : %d\n", a != b);

printf("\n---- Logical Operators ----\n");


printf("(a > 0 && b > 0) : %d\n", (a > 0 && b > 0));
printf("(a > 0 || b < 0) : %d\n", (a > 0 || b < 0));
printf("!(a > b) : %d\n", !(a > b));

printf("\n---- Bitwise Operators ----\n");


printf("a & b = %d\n", a & b);
printf("a | b = %d\n", a | b);
printf("a ^ b = %d\n", a ^ b);
printf("~a = %d\n", ~a);
printf("a << 1 = %d\n", a << 1);
printf("a >> 1 = %d\n", a >> 1);

printf("\n---- Assignment Operators ----\n");


result = a;
printf("result = a : %d\n", result);
result += b;
printf("result += b : %d\n", result);
result -= b;
printf("result -= b : %d\n", result);
result *= b;
printf("result *= b : %d\n", result);
result /= b;
printf("result /= b : %d\n", result);
result %= b;
printf("result %%= b : %d\n", result);

printf("\n---- Increment/Decrement Operators ----\n");


printf("++a = %d\n", ++a);
printf("--b = %d\n", --b);
printf("a++ = %d (after increment: %d)\n", a++, a);
printf("b-- = %d (after decrement: %d)\n", b--, b);

printf("\n---- Conditional (Ternary) Operator ----\n");


result = (a > b) ? a : b;
printf("Max of a and b = %d\n", result);

You might also like