Language Elements

Object Oriented Concepts

Data Types

Key Words

Arrays

Pointers

Data Structures

Multithreading

Errors and Exception Handling

Interview Questions



Contact



What is C++?

C++ is a high level computing language which evolved as an object oriented extension of C. C++ is platform independent, as same edited code can run on Windows, Linux or Mac OS X. The compilation however varies from one platform to another.

Applications

C++ finds its use in variety of applications related to banking, academics, smartphones, video games, music players, Graphics etc. It is widely used programming language for academic teaching and research. A great compilation can be found at C++ Applications, personal web site of Computer Scientist and Engineer, Bjarne Stroustrup (the inventor of C++).

Program Structure

A typical C++ program can be divided into a header files (.h file) and source code (.cpp or .cc or .C file). Different library functions are declaired in the header file. Source code of the C++ program is organised into smaller units or modules by collections of functions (methods) and data members (fields), with atleast one main function. Execution of the program always starts from the main function, before directed to some other function. Functions call each other, as directed by implementation of the programming logic.

Development Cycle

A C++ development cycle consist of Edit, Compile, and Excecute. A C++ compiler gives access to variety of libraries. Source code can be edited using a text editor. A compiler translates the source code into an executable, (a machine-language), saved as .o extension file. The object file, by the process of Linking, produces an output executable file. In order to run the source code for an output, suitable compiler choice can be decided from the available options for each platform. Commonly, for windows, it can be visual C++, while on Linux, g++, and for Mac OS X, XCode.

C++ Libraries

Libraries extend the basic functionality of source code to perform various tasks. They mainly consist of Standard Template Library (STL) and modified form of inherited C Standard Library. STL provides default functionality. The function library is from the C language. Library functions are defined in the header file, with .h extension.

Example C++ Source Code

A basic example of a C++ source code with necessary illustrative comments is given below. Following C/C++ convention for comments, single line comments are placed after // and multiple line comments are enclosed within /* ---*/.

/* The C++ code here uses main function, and one additional welcome function to display output as a text message: Welcome to this C++ tutorial!. */

#include <iostream>   // This is commonly used C++ header for library which provides input/output functionality using streams.

/* namespace std declaired below contains all the classes, objects and functions of the standard C++ library. Without using the namespace directive one need to explicitly add std:: before every identifier of the standard library. */

using namespace std;

void welcome( );   // function prototype for welcome function

int main( ) // main function declaration!The return type must be int.

{
welcome( );   // calls "welcome function"
return 0;
// Main function is expected to return zero to indicate success. }

/* welcome functions as defined below using key word "void" do not return a value after the function executes. A void function after performing the task returns control back to the caller function (here main function). */

void welcome( ) // the welcome function definition.
{
cout<<"Welcome to this C++ tutorial!"<<endl;   // the output declaration
// as welcome function is void, so return declaration here is unnecessary.
}





Copyright © by Zafar Yasin. All rights reserved.