









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to the basics of c++ programming, covering comments, preprocessor directives, namespaces, and header files. It includes examples of single-line and multi-line comments, the use of the #include preprocessor directive, and the declaration of namespaces and global variables. The document also explains the purpose of header files and the role of the main() function in c++ programs.
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!










/***********************************************************^
Header Comments **********************************************************/pre-processor directivesglobal declarationsint main(){
declarations and executable statementsreturn 0; }//end block of main// comments required by some organizations!
/****************************************************** Sum two numbers******************************************************/#include <iostream.h>
//declares standard I/O library
int main()
//must have one and only one function named main
{
int number1, number2;
//declare two integer variables
cout << “enter two integers” << endl;
//prompt for input
cin >> number1 >> number2;
//input values for two variables from keyboard
cout << number1 + number2;
//output sum of two numbers to the screen
return 0; }//end block of main
Comments have two forms in C++
-^
//Single line comments
-^
/Multi-line comments/
/ Program #1 - A first C++ program.*
Enter this program, then
compile and run it.
*/ •^
This is a
comment
(C style)
-^
Ignored by the compiler i.e. can write anything and thecompiler won’t see it at all
-^
Multiline or single or mixed with code.
-^
Why use comments?
//
main()
is
where
program
execution
begins.
C++ style comment
-^
Compiler ignores the whole line
-^
If multiline comments, use // on each line
cout
<<
“Hello,
world!";
Think of
cout
as the monitor screen (
console output)
<<
gives direction of data;
Put to
or
Insertion
operator
Prints the entire string within quotes to the screen
-^
This whole line is a statement
-^
C/C++ Statement
that ends with a ;
#include
Tells
preprocessor
to include contents of the text file
iostream with your source code before compiling
-^
iostream has details about things that handle inputand output e.g. cout
-^
iostream is called an
include file
or
header file
This is called an
include
directive
or
preprocessor
directive
-^
Can also use <iostream.h>; then no need to use the namespace
construct on the next slide. Older version
environment variable
Get out of bed
Take off pajamas
Take a shower
Get dressed
Eat breakfast
Carpool to work
-^
Get out of bed
Take off pajamas
Get dressed
Take a shower
Eat breakfast
Carpool to work
-^