In this class, I learned about the operators that enable calculate or compare the variables.
Here's four types of operators that easily classified to explan their functions.
1. Assignment operator
- 'A = B' means that value 'B' should be assigned to variable 'A'
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a;
a = 123;
printf('%d', a);
return 0;
}
2. Relational operator
- Comparing the relationship between left and the right and results showed whether the operator is true or false.
- Examples: 'A > B', 'A >= B', 'A! = B'
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a;
int b;
a = 123;
b = 456;
printf('%d \n', a > b);
printf('%d \n', a >= b);
printf('%d \n', a == b);
printf('%d \n', a != b);
return 0;
}
3. Arithmetic operator
- Examples: 'A + B', 'A - B', 'A * B', 'A / B', 'A % B'
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a;
a = 123 + 1;
printf('%d \n', a);
a = 123 - 2;
printf('%d \n', a);
a = 123 * 3;
printf('%d \n', a);
a = 123 / 10;
printf('%d \n', a);
a = 123 % 7;
printf('%d \n', a);
return 0;
}
4. Incremental operator
- Examples: 'A ++' means 'A = A + 1 and 'A --' means 'A = A - 1'
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a;
a = 1;
printf('%d \n', a);
a = a + 1;
printf('%d \n', a);
a++;
pritnf('%d \n', a);
a--;
printf('%d \n', a);
return 0;
}
5. Compound substitution operator
- Examples: 'A += B' means 'A = A + B' and 'A -= B' means 'A = A - B'
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a;
a = 1;
printf('%d \n', a);
a = a + 2;
printf('%d \n', a);
a += 2;
printf('%d \n', a);
return 0;
}
'Study Meeting > 빡공단 30기' 카테고리의 다른 글
[Day 10] Operator 3: Bitwise Shift Operator (0) | 2023.01.11 |
---|---|
[Day 9] Operator 2: Logical Operators and Bit operators in C Language (0) | 2023.01.10 |
[Day 7] Quadratic expression for C Programming (0) | 2023.01.07 |
[Day 6] ASCII Code: How to represent letter in C Language? (1) | 2023.01.07 |
[Day 5] Standard input/output functions: scanf() and printf() (0) | 2023.01.05 |