Lecture - 03 - Fundamental of Programming
Lecture - 03 - Fundamental of Programming
1
Introduction to Programming
Lecture 03: Fundamental of Programming
A Simple c program
2
3 A Simple C Program
Output
4 A Simple C Program
Lines 1 and 2
begin with //, indicating that these two lines are comments.
Comments do not cause the computer to perform any action when the program
is run.
Comments are ignored by the C compiler and do not cause any machine-
language object code to be generated.
Comments also help other people read and understand your program.
5
A Simple C Program
You can also use /*…*/ multi-line comments in which
everything from /* on the first line to */ at the end of the line is
a comment.
Line 4
#include <stdio.h>
Instead of <stdio.h>
there are many other
preprocessor
directives in C
language
You will learn other
preprocessor
directives from time to
time in other chapters
9
10 A Simple C Program
Line 6
For now, simply include the keyword int to the left of main in each of
your programs.
WARNING! When using escape sequences, do not place a space between backslash and the control
character.
18 A Simple C Program
Reserved Word
19
A Simple C Program:
Reserved words in c
20 A Simple C Program
Using Multiple printfs
The printf function can print This is my first program in several different ways.
For example, the program 3.2 produces the same output as the program 3.1
This works because each printf resumes printing where the previous printf stopped
printing.
The first printf (line 8) prints This is my followed by a space and the second printf
(line 9) first program begins printing on the same line immediately following the
space.
21 A Simple C Program (Using Multiple printfs)
Output
22 A Simple C Program: Printing a Line of Text
(Cont.)
One printf can print several lines by using additional newline
characters as in Program 3.3
Each time the \n (newline) escape sequence is encountered, output
continues at the beginning of the next line.
23
A Simple C Program (Print Multiple lines
using single printf)
Output
Another Simple C Program:
Entering Two Numbers
Printing the address of variables
25 Another Simple C Program: entering Two
numbers
Our next Program 3.4 uses the Standard Library function scanf to
obtain two numbers typed by a user at the keyboard, prints both
numbers using printf.
26
Another Simple C
Program: entering
Two numbers
Output
27 Another Simple C Program: entering Two
numbers
Variables and Variable Definitions
Lines 8–9
int number1;
int number2;
but that would have made it difficult to describe the variables with corresponding
comments as we did in lines 8–9.
29 Another Simple C Program: entering Two
numbers
A declaration is a syntactical element that associates a type with a
program entity, such as a variable.
Variables
Data type
30 Another Simple C Program: entering Two
numbers
Identifiers and Case Sensitivity
A data type is a set of data values and a set of operations on those values.
Usually has three classes of data types:
Output
43 Another Simple C Program: entering Two
numbers
Value 7 10
Data type & Variable int number1 int number2
Address 62FE4C 62FE48
56
Thank ANY
You QUESTIONS?