First Program
First Program
Introduction to C Programming
CPU
Input Device ALU CU Output Device
6
Machine Languages, Assembly Languages,
and High-level Languages
• Three types of computer languages
1. Machine language
• Only language computer directly understands
• Defined by hardware design
• Machine-dependent
• Generally consist of strings of numbers
• Ultimately 0s and 1s
• Instruct computers to perform elementary operations
• One at a time
• Cumbersome for humans
• Example:
1000110101 7
1001000101
1001110110
Machine Languages, Assembly Languages,
and High-level Languages
• Three types of computer languages
2. Assembly language
• English-like abbreviations representing elementary
computer operations
• Clearer to humans
• Incomprehensible to computers
• Translator programs (assemblers)
• Convert to machine language
• Example:
LOAD BASEPAY
ADD OVERPAY 8
STORE GROSSPAY
Machine Languages, Assembly Languages,
and High-level Languages
• Three types of computer languages
3. High-level languages
• Similar to everyday English, use common mathematical
notations
• Single statements accomplish substantial tasks
• Assembly language requires many instructions to
accomplish simple tasks
• Translator programs (compilers)
• Convert to machine language
• Interpreter programs
• Directly execute high-level language programs 9
• Example:
grossPay = basePay + overTimePay
C History
• Developed between 1969 and 1973 along with Unix
• Due mostly to Dennis Ritchie
• Designed for systems programming
• Operating systems
• Utility programs
• Compilers
• Filters
• Evolved from B, which evolved from BCPL
10
C Programming Environment
Preprocess/
Compile/
Link
Load/
Edit Run
11
First C Program
int main()
All C programs have a main function;
they also start at main
{
printf (“Welcome to C!\n”);
Function to print to screen
return 0;
What to print End of
} Braces indicate start statement 12
and end of main End of line
Try this…
• Print the following to the monitor using C program:
A * *****
BB ** * *
CCC *** *****
**
* *
* *
* * 13
* *
Identifiers
Names for variables, functions, macros, and other entities are called
identifiers.
An identifier may contain
letters,
digits, and
underscores,
but must begin with a letter or underscore:
times10 get_next_char _done
Examples of illegal identifiers:
10times get-next-char
C is case-sensitive: it distinguishes between upper-case and lower-
case letters in identifiers.
14
• For example, the following identifiers are all different:
job joB jOb jOB Job JoB JOb JOB
Keywords
Words reserved by the Programming Language for use by itself.
You can’t use them as identifiers.
Keywords
16
Data Type and Format
Specifiers
• Data types tells the compiler about the type of data so that it
can reserve memory for data. Format specifiers are used in
printf and scanf to specify the data type.
#include <stdio.h>
int main()
{
int height, length, width, volume;
21
Good Luck!
22