forked from portfoliocourses/c-example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment.c
43 lines (35 loc) · 848 Bytes
/
assignment.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*******************************************************************************
*
* Program: Assignment operator examples
*
* Description: Examples of how to use assignment operators in C.
*
* YouTube Lesson: https://www.youtube.com/watch?v=a2cbw2jkyMA
*
* Author: Kevin Browne @ https://portfoliocourses.com
*
*******************************************************************************/
#include <stdio.h>
int main(void)
{
int a;
// standard assignmen operator assigns 5 to a
a = 5;
printf("a: %d\n", a);
// adds 2 to a
a += 2;
printf("a: %d\n", a);
// subtracts 2 from a
a -= 2;
printf("a: %d\n", a);
// multiples a by 2
a *= 2;
printf("a: %d\n", a);
// divides a by 2
a /= 2;
printf("a: %d\n", a);
// sets a to the remainder of a divided by 2
a %= 2;
printf("a: %d\n", a);
return 0;
}