The C compound statements to simplify the C syntax program example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: How to simplify the C syntax using the compound statements

To show: The C compound statements to simplify the C arithmetic syntax program example

 

 

#include <stdio.h>

 

int main(void)

{

int a = 3, b = 4;

 

printf("Initially: a = 3, b = 4\n");

printf("\na += b ---> a = a + b = %d\n",a+=b);

printf("a last value = %d\n",a);

printf("\na *= b ---> a = a * b = %d\n",a*=b);

printf("a last value = %d\n",a);

printf("\na -= b ---> a = a - b = %d\n",a-=b);

printf("a last value = %d\n",a);

printf("\na/=b ---> a = a / b = %d\n",a/=b);

printf("a last value = %d\n",a);

printf("\na-=(b+1)---> a = a - (b + 1) = %d\n",a-=(b+1));

printf("a last value = %d\n",a);

 

return 0;

}

 

Output example:

 

Initially: a = 3, b = 4

a += b ---> a = a + b = 7

a last value = 7

a *= b ---> a = a * b = 28

a last value = 28

a -= b ---> a = a - b = 24

a last value = 24

a/=b ---> a = a / b = 6

a last value = 6

a-=(b+1)---> a = a - (b + 1) = 1

a last value = 1

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index