P. 1


|Views: 1|Likes:
Published by Muhammad rehan baig
c++ lesson
c++ lesson

More info:

Published by: Muhammad rehan baig on Jul 30, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less





Every language has its own language processor (or translator), therefore language processor is defined. 1. Compilers 2. Interpreters 3.

Assemblers Compiler: the language processor that translates the complete source program as a whole in machine code before execution is called compiler. Examples C or C++ compilers. Interpreter: the language processor that translates (converts) one statement of source program into machine code at a time and executes it immediately before translation the next statement is called interpreter. If there is an error in the statement, the interpreter terminates its translating process at that statement and displays an error message. Example: GW-Basic is an example of interpreter. Assembler: it is used to translate the program written in Assembly language into machine code. Basic Structure of C++ Program: the format or way according to which a computer program is written is called the Structure of the program. The program structure of different programming language is different. The basic structure of C++ program is very simple. The basic structure of the C++ program is given as under: a) Preprocessor Directives b) The main() Function c) C++ statements Example Program: #include <iostream.h> main() { cout << “My First Program is C++”; } Preprocessor Directives: the instructions that are given to the C++ compiler at the beginning of the source code are called preprocessor directives. The preprocessor directives are known as compiler directives. Note: Preprocessor directive does not end with semicolon (;). Most important preprocessor directives are: 1. include directive 2. define directive Detail of include and define directive will be discussed in later lessons. main() Function: C++ consists of one or more functions. Every C++ program must have the main() function. The main function indicates the beginning of the actual C++ program. It is the point at which execution of program is started. C++ Statements: the program statement is the fundamental unit of any programming language. The set of statements of C++ program are written under the main() function (or any user defined function) between curly brackets i.e {}. Every Statement of C++ must be terminated with semicolon (;). It is called statement terminator. If ; is missing, an error message is reported. (Statement missing)

variables are used to store values during program execution. 0000 0001 0002 0003 0004 0005 25 i Variable is: i 0002 25 Memory location Value . Logical errors 3. The name of memory location or variable name remains fixed during execution of program but the data stored in that location may change from time to time. Some basic data types of C++ are: 1. A variable represents a location in the computer’s memory where a value is stored for use of a program. The data is processed according to the program instructions and output is returned. Keywords: the predefined words of the C++ that are used for special purpose in the source program called keywords.) at the end. Some keywords are given below false if for while int float double char void new true do delete sizeof struct class Data types in C++: A computer program manipulates various types of data. Each statement is C++ written in lower case letters because C++ case sensitive language. The keywords are also known as reserved words.).We can write single statement in multiple lines but each statement must have (. There are three types of error that can occur in C++ program. We can write multiple statements in single line but each statement end with (. For example keyword ‘int’ can’t be used as variable name because it is used to define integer type variable. In C++ each variable is associated with a specific data type. 2. Runtime errors The detail will be discussed later on. These are: 1. int float double char void Variables: in any programming language. 3. 5. 4. The data is given to the program as input. Syntax errors 2.

First character must be letter or underscore (a to z or _) like number1. ^. 6.~ etc. int etc) Length of variable name can be from 1 to 31 characters. Meaningful name should be given to variables.not valid) Keywords can’t be used as variable name like (float. 5. No blank spaces between the variable name like ( number 1. 4. total etc. 3. A variable name declared for one data type. the same can’t be declared for another data type. 2. # . such as arithmetic operators.Rules for Naming the Variables: 1. total marks ……. Special characters. . 7. true.

You're Reading a Free Preview
