A Simple C++ Program
2 //Text-printing program.
3 #include
4 using namespace std;
5 // function main begins program execution
6 int main()
7 {
8 cout << "Welcome to C++!\n"; // display message
9
10 return 0; // indicate that program ended successfully
11 } // end function main
Comments
Used to describe program/* and */ is multiline comment
// is single line comment
Text starting with // or surrounded by /* and */ is ignored by computer
#include
Preprocessor directive
Tells computer to load contents of a certain file
int main()
C++ programs contain one or more functions, exactly one of which must be main
Parenthesis used to indicate a function
int means that main "returns" an integer value
Braces ({ and }) indicate a block
The bodies of all functions must be contained in braces
cout << “Hello World\n”;
Instructs computer to perform an action
Specifically, prints the string of characters within quotes (“ ”)
Entire line called a statement
All statements must end with a semicolon (;)
Escape character (\)
\n is the newline character
<< insertion operator or put to operator
return 0;
A way to exit a function
return 0, in this case, means that the program terminated normally
Right brace }
Indicates end of main has been reached
Linker
When a function is called, linker locates it in the library
Inserts it into object program
If function name is misspelled, the linker will produce an error because it will not be able to find function in the library
Data Types
- int
- float
- double
- char
- bool
- void
Memory Concept
Variables
Variable names correspond to locations in the computer's memory
Every variable has a name, a type, a size and a value
Whenever a new value is placed into a variable (=), it replaces (and destroys) the previous value
Reading variables from memory does not change them
Variable
- variable can hold a number or a data of other types, it always holds something. A variable has a name
- the data held in variable is called value
- variables are implemented as memory locations and assigned certain memory address. The exact address depends on computer and compiler.
- we think as though the memory locations are actually labeled with variable names
Identifier
identifier – name of a variable or any other named construct
identifier must start with a letter or underscore symbol (_), the rest of the characters should be letters, digits or underscores
the following are legal identifiers:
x x1 x_1 _abc sum RateAveragE
the following are not legal identifiers. Why?
13 3X %change data-1 my.identifier a(3)
C++ is case sensitive:
MyVar and myvar are different identifiers
Great way of posting buddy thanks For Sharing With us
ReplyDeleteI think I have never watched such online diaries ever that has absolute things with all nuances which I need. So thoughtfully update this ever for us.
ReplyDelete360DigiTMG big data course malaysia
I see the best substance on your blog and I unbelievably love getting them.
ReplyDeletehttps://360digitmg.com/india/data-science-using-python-and-r-programming-in-delhi
Guaranteed Expectations Are The Best Resources For Sales
ReplyDeleteGuaranteed Expectations Are The Best Resources For Sales
ReplyDelete
ReplyDeleteThe writer is amped up for purchasing wooden furniture on the web and his examination about best wooden furniture has accomplished the blueprint of this article.
supply chain management courses
Cognex is the AWS Training in Chennai. Cognex offers many offers during this diwali 2020. Cognex providing courses both in offline and online.
ReplyDelete