Lec 05
Lec 05
programming
Lecture 5
Acknowledgement: Some images of these slides come from the book:
C how to program
2. Assembly languages
• Symbolic abbreviations representing elementary computer
operations (translated into machine code via assemblers)
• Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
1. Edit Compiler
Compiler creates
Disk object code and stores
it on disk.
2. Preprocess Linker Disk Linker links the object
code with the libraries
Primary Memory
3. Compile
Loader
Loader puts program
4. Link in memory.
Disk ..
..
..
Comments
– Text surrounded by /* and */ is ignored by computer
– Used to describe program
• #include <stdio.h>
– Preprocessor directive
• Tells computer to load contents of a certain file
– <stdio.h> allows standard input/output operations
CC2005 (10/11) Sem 1 - L5 17
A Simple C Program: Printing a
Line of Text (2)
• int main()
– C programs contain one or more functions, exactly
one of which must be main
– Parenthesis used to indicate a function
– int means that main "returns" an integer value
– Braces ({ and }) indicate a block
• The bodies of all functions must be contained in braces
Addition + f+7 f + 7
Subtraction - p–c p - c
Multiplication * bm b * m
Division / x/y x / y
Modulus % r mod s r % s
• Executable statements
– Perform actions (calculations, input/output of data)
– Perform decisions
• May want to print "pass" or "fail" given the value of a test grade
• if control statement
– Simple version in this section, more detail later
– If a condition is true, then the body of the if statement will be
executed
• 0 is false, non-zero is true
– Control always resumes after the if structure
• Keywords
– Special words reserved for C
– Cannot be used as identifiers or variable names
≠ != x != y x is not equal to y
Relational Operators
> > x > y x is greater than y
Operators Associativity
* / % left to right
+ - left to right
< <= > >= left to right
== != left to right
= right to left
Fig. 2.14 Precedence and associativity of the operators discussed so far.
Keywords
– Important in program
development in team and
maintenance