Programming in C

(Barry) #1
Comments 17

The first program statement declares three variables called value1,value2,and sumall to
be of type int.This statement could have equivalently been expressed using three sepa-
rate declaratory statements as follows:


int value1;
int value2;
int sum;


After the three variables have been declared, the program assigns the value 50 to the
variable value1and then assigns 25 to value2.The sum of these two variables is then
computed, and the result is assigned to the variable sum.
The call to the printfroutine now contains four arguments. Once again, the first
argument, commonly called the format string, describes to the system how the remaining
arguments are to be displayed.The value of value1is to be displayed immediately fol-
lowing the display of the characters “The sum of.” Similarly, the values of value2and
sumare to be printed at the appropriate points, as indicated by the next two occurrences
of the %icharacters in the format string.


Comments


The final program in this chapter (Program 3.6) introduces the concept of the comment.
A comment statement is used in a program to document a program and to enhance its
readability. As you will see from the following example, comments serve to tell the reader
of the program—the programmer or someone else whose responsibility it is to maintain
the program—just what the programmer had in mind when he or she wrote a particular
program or a particular sequence of statements.


Program 3.6 Using Comments in a Program


/ This program adds two integer values
and displays the results
/


#include <stdio.h>


int main (void)
{
// Declare variables
int value1, value2, sum;


// Assign values and calculate their sum
value1 = 50;
value2 = 25;
sum = value1 + value2;
Free download pdf