About Me

Hello there! Before talking about qualifications and professional abilities, I would like to introduce myself. I am a Yuvraj Basnet and professional software developer and have been working in this field for 3 long years. I have finished my graduation from The University of Delhi on Computer Science Engineering I considered myself a reasonably experienced programmer with a particular interest in the human side of software development, computers are fascinating machine, but they're mostly reflection of the people using them. In the art of software development, studying code isn't enough; you have to study the people behind the software, too.

Basic Syntax And Program Structure of C++

Basic Syntax And Program Structure of C++

Basic Syntax of C++:

Hi there! welcome to the second tutorial on C++ programming language in this tutorial we will discuss basic syntax and program structure of C++.

When we examine a C++ program, it can be defined as a collection of objects that communicate via invoking each other's methods. Now let us briefly look into the class, object, methods and instance variable.

Object − Objects have behaviors and states. Example: A dog has states - name, color,  breed as well as behaviors - barking, wagging, eating. An object is an instance of a class. whenever we discussing this word instance it means that some memory spaces are getting allocated during the run time of the program so whenever some memory spaces are getting allocated we know who is really called this one as instance or instantiation.

Class − A class can be defined as a blueprint that describes the states/behaviors that object of its type support.

Methods − A method is basically a behavior. A class can contain many methods in a program. It is in methods where the  data is manipulated and logic's are written, and all the actions are executed. This method can also be called as class methods and member functions or member methods. so in a class will be having mind to be a number of methods which will be deciding that what are actions, activities that respective class can do. 

Instance Variables − Each object in a program has its different set of instance variables. An object's state is generated by the values assigned to these instance variables and this instance variable can also be called as member variables that means the variable which will be residing in an object to hold the certain values and so on.

Program Structure of C++:

A C++ programs can basically consists of the following parts:
1. Header file declaration section
2. Global declarations (if any) 
3. Namespace
4. Main Functions
5. Statements and Expressions
6. User defined functions

let us write simple code to print "Hello world" in C++:

Now we will look various parts of the above "Hello World" program:

1. The C++ defines several headers, which contain information that is either to your program. For this program, the header <iostream> is needed. So in case of iostream, iostream is a very common header file usually included in almost all C++ programs and this header file is pure text file you can open it in your editor and read the contents and it is containing the respective the function prototypes, constants. Actually the function code is residing in the respective library files.   

2. The next line using namespace std; sends the message to the compiler to use the std namespace. It is declarative region that provides scopes to the identifier (name of the types, functions/variables etc.). Namespaces are a recent addition to C++. Without defining a namespace program may not work and a common declarative area where you are suppose to keep the declarations of functions/variable and so on.

3. 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 termination of the line.

4. The next line in a program is int main() which is the main function where program execution must begins.

5. The next line cout << "Hello World"; causes the message "Hello World" to be displayed on the screen.

6. The next line return 0; ends main( )function and causes it to return the value 0 to the calling process.

Post a Comment