Elements of a C Program - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Elements of a C Program

Description:

Elements of a C Program. Hello World. The Hello World Program // the Hello World program ... need iostream.h to be able to use cout // the Hello World program ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 23
Provided by: Shep166
Category:

less

Transcript and Presenter's Notes

Title: Elements of a C Program


1
Elements of a C Program
  • Hello World

2
The Hello World Program
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
3
Starts comments
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
4
Comments
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
5
Preprocessor directive
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
6
Include a file
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
7
Include the file iostream.hneed iostream.h to be
able to use cout
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
8
Find the file in the standard placeC\Program
Files\Microsoft Visual Studio\VC98\Include\
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
9
The main function
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
10
Main function returns an integer
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
11
Encloses the main function
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
12
Used to print to the screen
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
13
Insertion operator
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
14
Contains a string
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
15
String to be printed to the screen
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
16
Indicates newline
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
17
Terminates a statement
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
18
Exit the function
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
19
Value returned from function
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
20
A brief look at cout
// Listing 2.2 using cout include
ltiostream.hgt int main() cout ltlt "Hello
there.\n" cout ltlt "Here is 5 " ltlt 5 ltlt
"\n" cout ltlt "The manipulator endl writes a new
line to the screen." ltlt endl cout ltlt "Here is a
very big number\t" ltlt 70000 ltlt endl cout ltlt
"Here is the sum of 8 and 5\t" ltlt 85 ltlt
endl cout ltlt "Here's a fraction\t\t" ltlt
(float) 5/8 ltlt endl cout ltlt "And a very very
big number\t" ltlt (double) 7000 7000 ltlt
endl cout ltlt "Dont't forget to replace Jesse
Liberty with your name...\n" cout ltlt "Tom Ray
is a C programmer!\n" return 0
21
Types of comments
include ltiostream.hgt int main() / this is a
comment and it extends until the
closing star-slash comment mark / cout ltlt
"Hello World!\n" // this comment ends at the
end of the line cout ltlt "That comment
ended!\n" // double slash comments can be alone
on a line / as can slash-star comments
/ return 0
22
Functions
include ltiostream.hgt // dunction Demonstration
Function // prints out a useful message void
Demonstration Function() cout ltlt "In
Demonstration Function\n" // function main -
prints out a message, then // calls
DemonstrationFunction, then prints out // a
second message. int main() cout ltlt "In
main\n" DemonstrationFunction() cout ltlt "Back
in main\n" return 0
Write a Comment
User Comments (0)
About PowerShow.com