<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}
.topnav {
  overflow: hidden;
  background-color: #f2f2f2;
}
.topnav a {
  float: left;
  color: #000080;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size:20px;
}

.topnav a:hover {
  background-color: #ddd ;
  color: black;
}

.topnav a.active {
  background-color:#000080  ;
  color:white;
}

header, footer {
    padding: 1em;
    color: white;
    background-color: #000080;
    clear: left;
    font-size:large;
    text-align: center;
}

nav {
    float: left;
    max-width: 180px;
    margin: 0;
    padding: 1em;
}

nav ul {
    list-style-type: none;
    padding: 0;
    font-size:20px;
}

nav ul a {
    text-decoration: none;
}

article {
    margin-left: 170px;
    border-left: 1px solid gray;
    padding: 1em;
    overflow: hidden;
} 
.icon-bar a {
    float: left;
    width: 5%;
    text-align: center;
    padding: 13px 0;
    color: #000080;
    font-size: 25px;
}
.vertical-menu {
    width: 180px;
}

.vertical-menu a {
    background-color:#eee;
    color:black;
    display: block;
    padding:15px;
    text-decoration: none;
}

.vertical-menu a:hover {
    background-color: #ccc;
}

.vertical-menu a.active {
    background-color: #000080;
    color: white;
}
a{
    text-decoration: none;
    display: inline-block;
    padding: 9px 17px;
}

a:hover {
    background-color: #ddd;
    color: black;
}

.previous {
    background-color:#000080;
    color: white;
}

.next {
    background-color: #000080;
    color: white;
	margin-left:780px;
}

</style>

</head>
<body>
<header>
<h1>CPP Programming</h1>
</header>

<div class="topnav">
  <div class="icon-bar"> <a class="" href="index.html"><i class="fa fa-home"></i></a> </div>
<a href="allprolang.html">All Languages</a>
  <a href="c_overview.html">C</a>
  <a class="active" href="cpp_overview.html">CPP</a>
  <a href="java_overview.html">JAVA</a>
  <a href="html_overview.html">HTML</a>
  <a href="css_overview.html">CSS</a>
  <a href="javascript_overview.html">JAVASCRIPT</a>
  <a href="python_overview.html">PYTHON</a>
  <div class="icon-bar"> <a class="" href="#"><i class="fa fa-search"></i></a> </div></div> 
<nav>
<div class="vertical-menu">
<a href="cpp_overview.html">Overview</a>
<a href="cpp_envrnmnt.html">Environment Setup</a>
<a class="active" href="cpp_basicsyntax.html">Basic Syntax</a>
<a href="cpp_comments.html">Comments</a>
<a href="cpp_datatypes.html">Data types</a>
<a href="cpp_variables.html">Variable Types</a>
<a href="cpp_constliterals.html">Constants &literas </a>
<a href="cpp_modifiertypes.html">Modifier Types</a>
<a href="cpp_storageclasses.html">Storage Classes</a>
<a href="cpp_operators.html">Operators</a>
<a href="cpp_loops.html">Loops</a>
<a href="cpp_decisionmake.html">Decision Making</a>
<a href="cpp_functions.html">Functions</a>
<a href="cpp_arraays.html">Arrays</a>
<a href="cpp_strings.html">Strings</a>
<a href="cpp_pointers.html">Pointers</a>
<a href="cpp_references.html">References</a>
<a href="cpp_basicio.html">Basic Input&Output </a>
<a href="cpp_datastructures.html">Data Structures</a>
<a href="cpp_classobject.html">Classes&Objects </a>
<a href="cpp_inheritance.html">Inheritance </a>
<a href="cpp_overloading.html">Overloading</a>
<a href="cpp_polymorphism.html">Polymorphism</a>
<a href="cpp_encapsulation.html">Encapsulation</a>
<a href="cpp_interfaces.html">Interfaces</a> 
</div> </nav>
<article>
<a href="cpp_envrnmnt.html" class="previous">&laquo; Previous</a>
<a href="cpp_comments.html" class="next">Next &raquo;</a>
<h1 style="color:#000080">BasicSyntax In CPP</h1><p>
When we consider a C++ program, it can be defined as a collection of objects that communicate via invoking each other's methods. Let us now briefly look into what a class, object, methods, and instant variables mean.</p>
<img src="images/cpp_syntax1.png"/>
<h3>C++ Program Structure</h3>
<p>Let us look at a simple code that would print the words Hello World.
</p>
<img src="images/cpp_syntax2.png"/> <h5>
Let us look at the various parts of the above program -</h5>
<ul>
<li>The C++ language defines several headers, which contain information that is either necessary or useful to your program. For this program, the header <iostream> is needed.
</li><li>
The line using namespace std; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++.
</li><li>
The next line '// main() is where program execution begins.' is a single-line comment available in C++. Single-line comments begin with // and stop at the end of the line.
</li><li>
The line int main() is the main function where program execution begins.
</li><li>
The next line cout << "Hello World"; causes the message "Hello World" to be displayed on the screen.
</li><li>
The next line return 0; terminates main( )function and causes it to return the value 0 to the calling process.
</li></ul>
<h3>
Compile and Execute C++ Program</h3>
<ul>
<h5>Let's look at how to save the file, compile and run the program. Please follow the steps given below -</h5>
<li>
Open a text editor and add the code as above.
</li><li>
Save the file as: hello.cpp
</li><li>
Open a command prompt and go to the directory where you saved the file.
</li><li>
Type 'g++ hello.cpp' and press enter to compile your code. If there are no errors in your code the command prompt will take you to the next line and would generate a.out executable file.
</li><li>
Now, type 'a.out' to run your program.
</li><li>
You will be able to see ' Hello World ' printed on the window.
</li></ul> 
<p>
Make sure that g++ is in your path and that you are running it in the directory containing file hello.cpp. 	 
</p><h3>
Semicolons and Blocks in C++</h3>
<p>
In C++, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.
<br>
For example, following are three different statements -
</p>
<img src="images/cpp_syntax4.png"/><p>
A block is a set of logically connected statements that are surrounded by opening and closing braces. For example -</p>
<img src="images/cpp_syntax5.png"/><p>
C++ does not recognize the end of the line as a terminator. For this reason, it does not matter where you put a statement in a line. For example -</p>
<img src="images/cpp_syntax6.png"/>
<h3>C++ Identifiers</h3>
<p>
A C++ identifier is a name used to identify a variable, function, class, module, or any other user-defined item. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9).
<br>
C++ does not allow punctuation characters such as @, $, and % within identifiers. C++ is a case-sensitive programming language. Thus, Manpower and manpower are two different identifiers in C++.
<br>
Here are some examples of acceptable identifiers -</p>

<img src="images/cpp_syntax7.png"/>
<h3>C++ Keywords</h3>
<p>
The following list shows the reserved words in C++. These reserved words may not be used as constant or variable or any other identifier names.
</p><img src="images/cpp_syntax8.png"/>
<br><img src="images/cpp_syntax9.png"/>
<h3>Trigraphs</h3><p>
A few characters have an alternative representation, called a trigraph sequence. A trigraph is a three-character sequence that represents a single character and the sequence always starts with two question marks.<br>

Trigraphs are expanded anywhere they appear, including within string literals and character literals, in comments, and in preprocessor directives.
<br>
Following are most frequently used trigraph sequences -</p>
<br><img src="images/cpp_syntax10.png"/>
<p>All the compilers do not support trigraphs and they are not advised to be used because of their confusing nature.
</p><h3>
Whitespace in C++</h3>
<p>A line containing only whitespace, possibly with a comment, is known as a blank line, and C++ compiler totally ignores it.
<br>
Whitespace is the term used in C++ to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins.</p>
<h5>Statement 1</h5><p>In the above statement there must be at least one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them.</p>
<br><img src="images/cpp_syntax11.png"/>
<h5>Statement 2</h5>
<p>In the above statement 2, no whitespace characters are necessary between fruit and =, or between = and apples, although you are free to include some if you wish for readability purpose.</p>
<br><img src="images/cpp_syntax12.png"/><br>
<a href="cpp_envrnmnt.html" class="previous">&laquo; Previous</a>
<a href="cpp_comments.html" class="next">Next &raquo;</a><br>
</article>
<footer>Devoloped by LE's</footer>
</div>
</body>
</html>