C++ – The Basics

Hello World

Programs

Programs: To get a computer to do something, we need to tell it exactly in great details what to do. Such description of what to do is called program.

Programming: Programming is the activity to write and test such programs.

Programming Language: It is very difficult to tell the computer to do things in just plain English, as English if very loosely structured. So we need something with a specific grammar and well-defined vocabulary.

The classic first program

The first computer program you should always write in any language is “Hello World!”.

#include "../../../include/std_lib_facilities.h"

// This program outputs the message “Hello, World!” to the monitor
using namespace std;
int main()             // C++ programs start by executing the function main
{
cout << "Hello, World!\n";      // output “Hello, World!”
return 0;
}

The above programs output the text “Hello World!” on the console.

Compilation

C++ is a compiled language. This means that to get a program to run, you must first translate the program from a human readable form to a machine readable form which it can understand. This translation is generally done by a program called a Compiler.

Job of a compiler::
1. Reads the source code.
2. Looks to see if the code is grammatically correct.
3. Every word have a defined meaning.
4. Any thing is obviously wrong that can be detected without actually running the code.

Each C++ statement ends with a ;, just remember “Put a semicolon after every expression that doesn’t ends with a right curly braces (})”

Linking

A program usually consist of several parts, often developed by different people. These separate parts must be compiled and the resulting object code files should be linked together to form an executable programs. The program that links together such parts are called a Linker

Object code and executable codes are not portable among systems.

Errors found by the compiler are called Compile time error, errors found by the linker are called link-time error. Errors not found until the program is executed is called run time error or logics errors

A Library is simply some code – usually written by others – that we access through the declaration given in a header file.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s