0% found this document useful (0 votes)
4 views4 pages

Programming

The document explains the difference between operators and operands in C, defining operators as symbols that specify operations and operands as the data items they act upon. It categorizes various types of operators in C, including arithmetic, relational, logical, bitwise, assignment, increment/decrement, conditional, sizeof, comma, and pointer operators. An example C program is provided to demonstrate the use of these operators in practice.

Uploaded by

kaneno karabu
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)
4 views4 pages

Programming

The document explains the difference between operators and operands in C, defining operators as symbols that specify operations and operands as the data items they act upon. It categorizes various types of operators in C, including arithmetic, relational, logical, bitwise, assignment, increment/decrement, conditional, sizeof, comma, and pointer operators. An example C program is provided to demonstrate the use of these operators in practice.

Uploaded by

kaneno karabu
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

Caleb koech

DCS/4492/2026

Differentiate between an operator and operand in C.

Operator – the symbol that specifies the operation to be performed.


Operand – the data item on which the operator acts.

Explain the different types of operators in C.

Category Description
Arithmetic Perform mathematical calculations.
Relational Compare values and produce a Boolean
result.
Logical Combine or invert Boolean expressions.
Bitwise Operate on individual bits of integer
types.
Assignment Assign values to variables.
Increment/Decrement Increase or decrease a variable’s value by
one.
Conditional (ternary)a Provide a shorthand if‑else expression.
sizeof Determine the size (in bytes) of a type or
variable.
Comma Separate multiple expressions where only
one is expected.
Pointer Access the address of a variable or the
value at an address.
example of a C program that demonstrates various operators:

#include

int main() {
int a = 10, b = 5, c;

// Arithmetic Operators
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); // Modulus operator

// Relational Operators
printf("\nRelational 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);

// Logical Operators
printf("\nLogical Operators:\n");
printf("a > 5 && b < 10: %d\n", a > 5 && b < 10);
printf("a > 5 || b > 10: %d\n", a > 5 || b > 10);
printf("!(a > 5): %d\n", !(a > 5));

// Assignment Operators
printf("\nAssignment Operators:\n");
c = a;
printf("c = a: %d\n", c);
c += a; // c = c + a
printf("c += a: %d\n", c);
c -= a; // c = c - a
printf("c -= a: %d\n", c);

// Increment/Decrement Operators
printf("\nIncrement/Decrement Operators:\n");
printf("a++: %d\n", a++); // Post-increment
printf("a: %d\n", a); // Value of a after increment
printf("b--: %d\n", b--); // Post-decrement
printf("b: %d\n", b); // Value of b after decrement

// Conditional Operator
printf("\nConditional Operator:\n");
int max = (a > b) ? a : b;
printf("Max of a and b: %d\n", max);
return 0;
}

You might also like