learning c and c++
DESCRIPTION
C character set Basic constants and variables Output function – printf Input function – scanf C instructionsTRANSCRIPT
![Page 1: Learning C and C++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/1.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/2.jpg)
2
Learning C/C++
![Page 3: Learning C and C++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/3.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/4.jpg)
4
C Character Set
![Page 5: Learning C and C++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/5.jpg)
5
Constants
An entity that doesn’t change
![Page 6: Learning C and C++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/6.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/7.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/8.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/9.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/10.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/11.jpg)
11
Variable Types
![Page 12: Learning C and C++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/12.jpg)
12
Keywords
Meaning already explained to compiler Cannot be used as variable name
![Page 13: Learning C and C++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/13.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/14.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/15.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/16.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/17.jpg)
17
Gross salary C Program
![Page 18: Learning C and C++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/18.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/19.jpg)
19
Gross salary C Program
![Page 20: Learning C and C++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/20.jpg)
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++](https://reader035.vdocuments.mx/reader035/viewer/2022062300/555e3343d8b42a63048b4674/html5/thumbnails/21.jpg)
21
21
End