C Programming: Absolute Beginner's Guide
C Programming: Absolute Beginner's Guide
Linking the linker combines one or more binary (.o files) into a single executable
file.
%07d will print out an integer with a minimum of 7 spaces and leading spaces will
contain 0s.
By default the number will be printed right aligned empty spaces will be to the
left of the number.
%.2f will print out a floating-point number with 2 decimal spaces to the right of the
decimal point. The .2 is referred to as a precision specifier.
%-10.3f will display a floating-point number in 10 spaces, with 3 decimal places, and
left-aligned. The minus sign specifies that the number be left aligned.
Developed by J. Woodcock; revised by M.
13
Anderson
Creating Variables
A variable is a box located in computer memory that holds a number or a character.
To create a variable it must be declared. A variable declaration has the
following syntax:
data_type variable_name;
A variable can be any name provided that it adheres to the following naming
convention:
Naming rule Example
Cannot contain any of the C keywords while
Cannot contain arithmetic operators a+b*c
Cannot contain non-alphanumeric characters %$#@!.,;:?/
Cannot contain any spaces number one
Cannot start with a number 2bad
Variables declarations must be made before they are used, and should be made
before any executable code in the function or in the file.
Initialization is when a value is first assigned to a variable; the equal sign is the
assignment operator (=).
Examples:
int num1, num2; /* Declares two integer variables. */
char letter; /* Declares a character variable. */
float decimal = 7.5; /* Declares and initializes a
floating-point variable */
num1 = 100; /* Initializes the integer variables. */
num2 = 200;
letter= B; /* Initializes the character variable */