Instructions And Operator
In the C language, instructions and operators are foundational concepts used to write programs that perform specific tasks.
🔹 Instruction in C
An instruction in C is a command given to the compiler to perform a specific operation. These form the building blocks of a C program. They tell the computer what to do.
Types of Instructions:
-
Type Declaration Instruction: Declares variables and their data types.
int a, b; float salary; -
Arithmetic Instruction: Performs arithmetic operations.
sum = a + b; product = a * b; -
Control Instruction: Directs the flow of execution.
-
Conditional:
if,if-else,switch -
Looping:
for,while,do-while -
Jumping:
break,continue,goto,return
if (a > b) { printf("A is greater"); } -
-
Input/Output Instruction: Used for reading input and displaying output.
scanf("%d", &a); printf("Value of a: %d", a);
🔹 Operator in C
An operator is a symbol that performs an operation on variables or values.
Categories of Operators:
-
Arithmetic Operators: Used for basic arithmetic operations.
-
+,-,*,/,%
c = a + b; -
-
Relational (Comparison) Operators: Compare two values.
-
==,!=,>,<,>=,<=
if (a != b) { ... } -
-
Logical Operators: Combine conditions.
-
&&(AND),||(OR),!(NOT)
if (a > 0 && b > 0) { ... } -
-
Assignment Operators: Assign values to variables.
-
=,+=,-=,*=,/=,%=
a += 5; // same as a = a + 5; -
-
Increment/Decrement Operators: Increase or decrease value by 1.
-
++,--
a++; // Post-increment ++b; // Pre-increment -
-
Bitwise Operators: Operate on binary data.
-
&,|,^,~,<<,>>
-
-
Conditional (Ternary) Operator: Short form for if-else.
-
condition ? expr1 : expr2;
int max = (a > b) ? a : b; -
-
Sizeof Operator: Returns the size of a data type or variable.
int size = sizeof(int);
