C Programming In Steps
29 Pages 7130 Words
b, some coming from the same program, and others from libraries.
One method of communicating data between functions is by arguments. The parentheses following the function name surround the argument list; here main is a function of no arguments, indicated by ( ). The {} enclose the statements of the function. Individual statements end with a semicolon but are otherwise free-format.
printf is a library function which will format and print output on the terminal (unless some other destination is specified). In this case it prints
hello, world
A function is invoked by naming it, followed by a list of arguments in parentheses. There is no CALL statement as in Fortran or PL/I.
3. A Working C Program; Variables; Types and Type Declarations
Here's a bigger program that adds three integers and prints their sum.
main( ) {
int a, b, c, sum;
a = 1; b = 2; c = 3;
sum = a + b + c;
printf("sum is %d", sum);
}
Arithmetic and the assignment statements are much the same as in Fortran (except for the semicolons) or PL/I. The format of C programs is quite free. We can put several statements on a line if we want, or we can split a statement among several lines if it seems desirable. The split may be between any of the operators or variables, but not in the middle of a name or operator. As a matter of style, spaces, tabs, and newlines should be used freely to enhance readability.
C has four fundamental types of variables:
int integer (PDP-11: 16 bits; H6070: 36 bits; IBM360: 32 bits)
char one byte character (PDP-11, IBM360: 8 bits; H6070: 9 bits)
float single-precision floating point
double double-precision floating point
There are also arrays and structures of these basic types, pointers to them and functions that return them, all of which we will meet shortly.
All variables in a C program must be declared, alt...