Title: Elements of a C Program
1Elements of a C Program
2The Hello World Program
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
3Starts comments
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
4Comments
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
5Preprocessor directive
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
6Include a file
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
7Include 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
8Find 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
9The main function
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
10Main function returns an integer
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
11Encloses the main function
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
12Used to print to the screen
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
13Insertion operator
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
14Contains a string
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
15String to be printed to the screen
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
16Indicates newline
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
17Terminates a statement
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
18Exit the function
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
19Value returned from function
// the Hello World program include
ltiostream.hgt int main() cout ltlt "Hello
World!\n" return 0
20A 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
21Types 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
22Functions
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