learning c and c++

21
Course: Course: Programming Fundamentals Programming Fundamentals 4.00 Credit Hours, Fall 2013, 4.00 Credit Hours, Fall 2013, Undergraduate Program Undergraduate Program Instructor: Maryam Ehsan Instructor: Maryam Ehsan SESSION 1, 2 SESSION 1, 2 © www.uogsialkot.edu

Upload: pagal-bacha

Post on 22-May-2015

602 views

Category:

Education


0 download

DESCRIPTION

C character set Basic constants and variables Output function – printf Input function – scanf C instructions

TRANSCRIPT

Page 1: Learning C and C++

Course:Course:

Programming FundamentalsProgramming Fundamentals4.00 Credit Hours, Fall 2013, 4.00 Credit Hours, Fall 2013,

Undergraduate ProgramUndergraduate ProgramInstructor: Maryam EhsanInstructor: Maryam Ehsan

SESSION 1, 2SESSION 1, 2

© www.uogsialkot.edu

Page 2: Learning C and C++

2

Learning C/C++

Page 3: Learning C and C++

3

Today’s lecture outline

C character set Basic constants and variables Output function – printf Input function – scanf C instructions

Page 4: Learning C and C++

4

C Character Set

Page 5: Learning C and C++

5

Constants

An entity that doesn’t change

Page 6: Learning C and C++

6

Integer Constants

Must have at least one digit It must not have a decimal point It can be either positive or negative If there is no sign an integer constant is

assumed to be positive No commas or blanks are allowed within

an integer constant Examples: 135, -67, 3401, -5670

Page 7: Learning C and C++

7

Real Constants

Also called Floating Point constants A real constant must have at least one digit It must have a decimal point It could be either positive or negative Default sign is positive No commas or blanks are allowed within a

real constant Examples: +325.34, 426.0, -32.76, -

48.5792

Page 8: Learning C and C++

8

Character Constants

A character constant is a single alphabet a single digit or a single special symbol

Enclosed within single inverted commas Both the inverted commas should point

to the left The maximum length can be 1 character Examples: ’A’, ‘I’, ‘5’, ‘=‘

Page 9: Learning C and C++

9

Variables… An entity that may vary during program

execution Names given to locations in memory

x = 3 x = 5

Page 10: Learning C and C++

10

Variables..

No commas or blanks are allowed within a variable name.

No Special symbol are used in name. Examples: Interger1, Sum, _FirstNum Invalid variable names

#sum, 12x, first name

Page 11: Learning C and C++

11

Variable Types

Page 12: Learning C and C++

12

Keywords

Meaning already explained to compiler Cannot be used as variable name

Page 13: Learning C and C++

13

Writing C/C++ Programs

Instructions as statements Order of statements Each statement must end with a ; Blanks for readability or clarity Case-Sensitive

Page 14: Learning C and C++

14

Variable Declaration14

Any variable used in the program must be declared first before using it.

int x; char my_Letter; Float time; double Result;

Page 15: Learning C and C++

15

Output function

printf ( "<format string>", <list of variables> ) ;

<format string> can contain,Format String Identifier

Single Character %c

Integer %d

Float %f

Double %lf

Page 16: Learning C and C++

16

Examples16

Printf(“The Letter is %c”, ’k’); Printf(“That pronounced as %s”, ’kay’); Printf(“Integer Input is %d”, 2); Printf(“Floating Point input id %f”,24.56);

Page 17: Learning C and C++

17

Gross salary C Program

Page 18: Learning C and C++

18

Input

To make gross salary calculation program general, the program ask the user to input value of hours and payrate during execution

scanf function is used to input value from user during program execution

Page 19: Learning C and C++

19

Gross salary C Program

Page 20: Learning C and C++

20

Input function syntax

Ampersand (&) before the variables in the scanf( ) function is a must.

& is an ‘Address of’ operator It gives the location number used by the

variable in memory

Page 21: Learning C and C++

21

21

End