50 : C Programming
Jinan Darwiche
1
Topics
Welcome to class
Computer languages
The compila<on process
The history of C
Developing programs with C
Helloworld.Cpp
2
Welcome to Class
Each unit contains a slides le, reading materials,
an assignment or a quiz, and Discussions
The slides are your star<ng point of the learning
process
Check the due dates of the assignments, quizzes
and or Discussion using our course site
Ask ques<ons in the Discussion if you have them;
you may also answer others ques<ons The
Discussion is our mee<ng place. Check it daily
3
Programming: Why do it?
Processor based devices such as desktops/
laptops, smart phones, electronic pads, even
some cars, TVs, etc execute instruc<ons, called
machine language soTware.
Instruc<ons are wriVen in a programming
language of your choice. This is called Source
Code.
Another soTware, called Compiler, changes the
source code into Assembly/Machine Code.
4
Computer languages
5
High-Level Languages
C oers convenient high-level language
features with access to low-level hardware
primi<ves
Languages are interpreted or compiled
C is a compiled language
6
Compiled Languages
Compiled languages must be turned into
executable computer instruc<ons
Preprocessor Linker
8
Developing Programs With C
Program Development Methodology
Analysis Design Implement Rollout Support
Understand, Model, Plan, Construct, Deliver Maintain
Study Think Fullfill
9
Visual Studio .NET 2012
10
Purpose of SoTware
Most of the soTware/programs we will learn
and write will follow the same paVern:
Get input
Process the input to product some result
Show output usually the result produced in the
previous step
11
Learning Programming
Analyzing exis<ng code helps in understanding
how to write code
In the early stages, you may not understand
every line focus on the main concepts
Syntax errors are very common be pa<ent
12
To Learn Programming You Learn
The syntax: What words and how to put them
together to form sentences
Words are referred to as keywords, and
sentences are referred to as statements
Each Programming language has its own syntax
The seman(cs: How to form statements to
solve a par<cular problem.
Seman<cs are universal not language
dependent
13
Time For Our First Demo: Hello World
Start VS 2012 then click New Project. You will get:
14
First <me you get the setup wizard
- Choose Console Applica<on
15
Click Finish
16
You will get a Blank Applica<on
Minimize the exis<ng code
Click -
17
What is Hello World
A star<ng point to learn how to show output.
Code is typically made of one statement to
show the words hello world as output.
18
Write the Code
21
ATer you type the code
Click the Debug buVon (green play icon)
You must always test if your code is syntax
error free and executes without errors.
If you get an error, you must x it
Run your code by clicking:
22
When you run.
The code we covered for Hello World, runs,
but you dont get to see it
The run<me Console screen appears then
quickly disappears
To make the Console stay, we need an input
statement
ATer the prinp line, add:
scanf_s("press any key");
23
C Code components
Include statements
main func<on
Statements inside func<ons
Comments: are lines that explain the code but the
compiler does not translate to machine language.
Comments can be single-line: // or extend over
mul<ple lines using /* */
Comments help programmers understand the code
later when they read it
24
Output in C
25
See book sec<on 5 note the dierences
between the book and our code-
Skip to sec<on 6 (The classical hello world
program).
26
Overview of C and Programming
Most programs get input from the user
Input in code is saved into Variables
Input is processed to produce some result
Results are also saved in var<ables
A variable is a loca<on in RAM, marked by its
name, and what type of informa<on it can
contain.
27
Read the book sec<ons 8, 9 and 10.
You may ignore sec<ons marked with links.
28
Next Unit
We learn how to get input, process it then
show output
This requires the use of variables, input and
output statements
Review the slides aTer reading the book
Post ques<ons in the Discussion
Complete the quiz/assignment
29