10/05/2016

C plus plus programming

SOMETHING ABOUT C++

DATA TYPES:-
char
int
float
double
void
bool
DATA TYPE MODIFIERS:-
signed
unsigned
long
short
Identifiers
hello_world
_abc
DEFINE
Reserved Words(Keywords)

  • Variable Declaration Words:-

char
double 
float

  • Statements Words:-

break
else
if 
case

  • Storage Allocation Identifier

const
volatile
static
void

Basic structure of C++ program

 The best way to learn a programming language is by writing programs. Typically, the first program beginners write is a program which simply prints "myeasycprogram" to your computer screen. Although it is very simple, it contains all the fundamental components of C++ programs :

// my first program in C++
#include <iostream>

int main()
{
  std::cout << "myeasycprogram";
}

Output:
myeasycprogram


Description of this program line by line:

 Line1:// my first program in C++
Lines beginning with two slash signs (//) are comments by the programmer and have no effect on the behavior of the program. Programmers use them to include short explanations or observations concerning the code or program. 

 Line2:#include <iostream>
Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor. They are special lines interpreted before the compilation of the program itself begins. In this case, the directive #include <iostream>, instructs the preprocessor to include a section of standard C++ code, known as header iostream, that allows to perform standard input and output operations, such as writing the output of this program to the screen.

Line3:A blank line.
Blank lines have no effect on a program. They simply improve readability.

Line 4: int main ()
This line initiates the declaration of a function. Essentially, a function is a group of code statements which are given a name: in this case, this gives the name "main" to the group of code statements that follow. 

The function named main is a special function in all C++ programs; it is the function called when the program is run. The execution of all C++ programs begins with the main function regardless of where the function is actually located within the code.

Lines 5 and 7: { and }
The open brace ({) at line 5 indicates the beginning of main's function definition, and the closing brace (}) at line 7, indicates its end. Everything between these braces is the function's body that defines what happens when main is called. All functions use braces to indicate the beginning and end of their definitions.

Line 6: std::cout << "myeasycprogram";
This line is a C++ statement. A statement is an expression that can actually produce some effect. It is the meat of a program, specifying its actual behavior. Statements are executed in the same order that they appear within a function's body.

Now we can also write the program as follows:

#include<iostream>
using namespace std;

int main()
{
cout<<"myeasycprogram";
}

Output:
myeasycprogram


C++ basic












No comments:

Post a Comment