5 Programming Basics and Overview of C
5 Programming Basics and Overview of C
OVERVIEW OF C
ANATOMY OF A C PROGRAM
program header comment
library
CONSTANT
▪ constant macro
▪ a name that is replaced by a particular constant value
before the program is sent to the compiler
int hours;
double miles;
VARIABLE (IDENTIFIER) DECLARATIONS
▪ There are two type of identifiers: standard identifiers
and user-defined identifiers.
▪ Standard identifiers, like scanf and printf, are
defined in standard libraries.
▪ Avoid using standard identifiers as variable names.
▪ User-defined identifiers are the names we give to
our constants, variables, functions, etc. in our
programs. We should obey some rules while we are
choosing our identifiers.
RULES FOR NAMING VARIABLES
▪ Can be of anything length, but only the first 31
characters are taken into consideration
▪ C is case sensitive. It matters whether an identifier,
such as a variable name, is uppercase or lowercase.
▪ SUM, Sum, and sum are considered as different variables.
meatballs
garbage
FE07 int
USING VARIABLES: INITIALIZATION
▪ Variables may be be given initial values, or initialized, when
declared. Examples:
length
int length = 7 ; 7
diameter
5.9
double diameter = 5.9 ;
initial
‘A’
char initial = ‘A’ ;
USING VARIABLES: INITIALIZATION (CON’T)
#define PI 3.14159
#define MAX 1000
#define BLANK ' '
Preprocessor
Compiler
Program Object Code File pgm.o
Other Object Code Files (if any)
Linker