Monday, April 1, 2013

The assignment operator (=)

A program that makes a few changes in variable values using the assignment operator

/* The = operator puts the value on the right */ /* into the variable on the left */
#include <stdio.h> int main (void) { /* declarations */ int a, b, c, d, e; /* fill variable a */ a = 10; /* modify variable a few times*/ a = 20; a = 10 + a; a = a + a + 2; a = 2 + a; /* a few more assignments */ b = a; c = b = 5; c = 10 + a; d = a + a + 2; e = 20 + a; a = a - b + c; /* the final values are... */ printf ("a:%4d\n b:%4d\n c:%4d\n d:%4d\n e:%4d\n", a, b, c, d, e); return (0); }
Legend: preprocessor directives | variable declarations | main program | helper functions | user-defined structures | comments
a: 133
b:   5
c:  74
d: 130
e:  84

No comments:

Post a Comment