The best way to learn C or C++ is to start coding right away. So here is our very first program in C++.

#include <iostream.h> //Allows to output data to screen
//function main begins program execution
int  main (void)
  int number1; // integer variable declaration
  cout<<"Welcome to C++"; // print on console
} // end of program

#include is a pre-processor directive. It is not part of our program; it is an instruction to the compiler. It tells the C compiler to include the contents of a file, in this case the system file iostream.h. The compiler knows that it is a system file, and therefore looks for it in a special place. The features of preprocessor will be discuss later.

<iostream.h> is the name of the library definition file for all Input Output Streams. Your program will almost certainly want to send stuff to the screen and read things from tkeyboard. iostream.h is the name of the file in which has code to do that work for you.

main() is the special function in C++. It is actually the one which is run when your program is used. A C program is made up of a large number of functions. Notice that parentheses contain nothing. There may be something written inside the parentheses.

cout  is known as out put stream in C and C++. Stream is a complicated thing, ylearn about it later. Think a stream as a door. The data is transferred through stream, cout takes data from computer and sends it to the output. For the moment it is a screen of the monitor. hence we use cout for output. The sign << indicates the direction of data. Here it is towards cout and the function ocout is to show data on the screen.

There is a semicolon (;) at the end of the above statement.

Variables in C++

During programming we need to store data. This data is stored in variables. Variaare locations in memory for storing data. The memory is divided into blocks. It caviewed as pigeon-holes.

A location in computer memory, where data can be stored for use by a program. All variables must be declared with a name and a data type before they can be used in any program. Several variable of the same data type can be declared in one declaration or in multiple declarations
int number1; int number2; int number3;
int number1, number2, number3;
For more than one variable, their names must be separated by commas  [ Comma-separated List]. Comma separated declaration reduces code but decreases readability of program. In a program a variable has

  • Name
  • Data Type
  • Size
  • Value

Every variable has a name. Any valid identifier that is not a keyword also called identifier. An identifier is a series of characters, consisting of letters, digits, and underscores (_) that doesn’t begin with digit. Must begin with a letter. Can be of anything length, but on the first 31 are significant (too long is as bad as too short). Are case sensitive e.g. abc is different from ABC.

Data type

Data type is the type of data a variable can store. Commonly used Data Types are:

  • int
  • short
  • long
  • float
  • double
  • char
  • bool
Fundamental types, Primitive types, or Built-in types

Every variable has some size that it holds in memory. We’ll not go into its detail however, where ever necessary we’ll notify the memory size.


Data types define range of values a variable can store. Whenever a value is placed in variable, it overwrites the previous value. This is called destructive process. Whenever a value is read out of a memory location it is called non-destructive process.
This was just an introductory lecture. In coming lectures, we’ll discuss in detail arithmetic expressions, mixed data type expressions, language constructs with more concrete examples.
Tagged with: C/C++ language

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.