<Practical C Programming> chapter 4
1. Elements of a program:
In computer programming, you need two things: data(variables) and instructions (code or functions).
variables are the basic building blocks of a program;
Instructions tell the computer what to do with the variables.
Comments are used to describle the variable and instructions.
2. Basic Program Structure:
the basic element of a program are the data declarations, functions, and comments.
the basic structure of a one-function program is:
Heading comments tell the programmer about the programm, and the data declartions describe the data that the program is going to use.
the single function is named main, a special one, because it's the first function called. the function main begins with:
int main()
{
and ends with:
return (0);
}
a non-zero status indicates an error--the bigger the return value, the more severe the error.
3. Simple Expressions:
simple operations:
operator meaning
* multiply
/ divide
+ add
- substract
% modulus (return the remainder after division)
*, /, and % have precedence over + and -. Parentheses, (), may be used to group terms.
4. Variable and storage:
C allow us to store values in variables. each variable is identified by a variable name. in addition, each variable has a variable type.
Names start with a letter or underscore(_), followed by any number of letters, digits, or underscores.
Case-sensitive.
Avoid variable names that similar, for they're confusing.
5. Variable Declarations:
A variable declaration serves three purposes:
1. It defines the name of the variable;
2. It defines the type of the variable;
3. It gives the programmer a description of the variable.
The general form of a variable declaration is:
type name; /* comment */
where tyoe is one of the C variable types and name is any valid variable name. this declaration explains what the variable is and what it will be used for.
6. Intergers
int name; /* comment */
limits.h
7. Assignment statements:
=
the general form of the assignment statement is:
variable = expression;
8. printf function:
printf(format, expression-1, expression-2, ...);
where format is the string describing what to print;
9. floating point:
float variable; /* comment */
10. Floating point versus integer divide:
expression result
int / int int
float / int float
int / float float
float / float float
11. characters:
char variable; /* comment */
the backslash character (\) is called the escape character, it is used to signal that a special character follows;
1. Elements of a program:
In computer programming, you need two things: data(variables) and instructions (code or functions).
variables are the basic building blocks of a program;
Instructions tell the computer what to do with the variables.
Comments are used to describle the variable and instructions.
2. Basic Program Structure:
the basic element of a program are the data declarations, functions, and comments.
the basic structure of a one-function program is:
/****************************************************
* ...Heading comments...
*
****************************************************/
...Data declarations...
int main()
{
...Executable statements...
return (0);
}
Heading comments tell the programmer about the programm, and the data declartions describe the data that the program is going to use.
the single function is named main, a special one, because it's the first function called. the function main begins with:
int main()
{
and ends with:
return (0);
}
a non-zero status indicates an error--the bigger the return value, the more severe the error.
3. Simple Expressions:
simple operations:
operator meaning
* multiply
/ divide
+ add
- substract
% modulus (return the remainder after division)
*, /, and % have precedence over + and -. Parentheses, (), may be used to group terms.
4. Variable and storage:
C allow us to store values in variables. each variable is identified by a variable name. in addition, each variable has a variable type.
Names start with a letter or underscore(_), followed by any number of letters, digits, or underscores.
Case-sensitive.
Avoid variable names that similar, for they're confusing.
5. Variable Declarations:
A variable declaration serves three purposes:
1. It defines the name of the variable;
2. It defines the type of the variable;
3. It gives the programmer a description of the variable.
The general form of a variable declaration is:
type name; /* comment */
where tyoe is one of the C variable types and name is any valid variable name. this declaration explains what the variable is and what it will be used for.
6. Intergers
int name; /* comment */
limits.h
7. Assignment statements:
=
the general form of the assignment statement is:
variable = expression;
8. printf function:
printf(format, expression-1, expression-2, ...);
where format is the string describing what to print;
9. floating point:
float variable; /* comment */
10. Floating point versus integer divide:
expression result
int / int int
float / int float
int / float float
float / float float
11. characters:
char variable; /* comment */
the backslash character (\) is called the escape character, it is used to signal that a special character follows;