Wednesday, 19 March 2014

Introduction


Introduction


C++ is a statically typed, compiled, general-purpose, case-sensitive, free-form programming language that supports procedural, object-oriented, and generic programming.
C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features.
C++ was developed by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray Hill, New Jersey, as an enhancement to the C language and originally named C with Classes but later it was renamed C++ in 1983.
C++ is a superset of C, and that virtually any legal C program is a legal C++ program.

 
 

Compilers

 
C++ is a language that has evolved much over the years, and these tutorials explain many features added recently to the language. Therefore, in order to properly follow the tutorials, a recent compiler is needed. It shall support (even if only partially) the features introduced by the 2011 standard.


Errors


There are several types of errors that you may face while writing a program. Some errors may be very common like typing mistakes. Such errors can be discovers by compiling the program. Also it may be the case that you have typed the program correctly but even after this you are not getting your expected output. So, some errors may appear at compile time while some may appear at run time. 
we shall later discuss the detailed study of errors.
 

C++ Program Structure:

Let us look at a simple code that would print the words Hello World.
 
#include <iostream>
using namespace std;
// main() is where program execution begins.
  int main()
{
   cout << "Hello World"; // prints Hello World
return 0;
}
 

Comments in C++

C++ supports single line and multi-line comments. All characters available inside any comment are ignored by C++ compiler.
C++ comments start with /* and end with */

A comment can also start with //, extending to the end of the line.


C++ Primitive Built-in Types:

C++ offer the programmer a rich assortment of built-in as well as user-defined data types. Following table list down seven basic C++ data types:
TypeKeyword
             Boolean                bool
             Character                char
             Integer                int
             Floating point                float
             Double floating point               double
             Valueless               void
            
 

Variable Definition & Initialization in C++:

int a = 3, b = 5; // definition and initializing a and b.
byte c = 22; // definition and initializes c.
char x = 'x'; // the variable x has the value 'x'.
 
 

C++ Variable Scope:

A scope is a region of the program and broadly speaking there are three places where variables can be declared:
  • Inside a function or a block which is called local variables,
  • In the definition of function parameters which is called formal parameters.
  • Outside of all functions which is called global variables.

 

C++ Constants/Literals:

Constants refer to fixed values that the program may not alter and they are called literals.
Constants can be of any of the basic data types and can be divided in Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values.
Again, constants are treated just like regular variables except that their values cannot be modified after their definition.

No comments:

Post a Comment