From 242826ea92c4087f5de6560aba78983134586932 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Tue, 3 Oct 2023 11:56:22 +0100 Subject: [PATCH] complete c7ex1 --- C6/ex1.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 C6/ex1.c diff --git a/C6/ex1.c b/C6/ex1.c new file mode 100644 index 0000000..2e15ea7 --- /dev/null +++ b/C6/ex1.c @@ -0,0 +1,28 @@ +#include +#include + +int main(void) +{ + // Declare some variables + int a, b; + + // Note: Order of a,b indicates the order in which operations are carried out on execution + + // Increment operators + b = 3; + printf("a=%d b=%d\n", a, b); + a = ++b; // b is now 4, a is also 4 + printf("a=%d b=%d\n", a, b); + a = b++; // a is 4, b is now 5, + printf("a=%d b=%d\n", a, b); + + // Decrement operators (reset a back to 3) + b = 3; + printf("a=%d b=%d\n", a, b); + a = b--; // a is 3, b is now 2 + printf("a=%d b=%d\n", a, b); + a = --b; // b is now 1, a is also 1 + printf("a=%d b=%d\n", a, b); + + return 0; // Exit from main +}