Anda di halaman 1dari 3

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)

We can write single statement in multiple lines but each statement must have (;) at the end. We can write multiple statements in single line but each statement end with (;). Each statement is C++ written in lower case letters because C++ case sensitive language. There are three types of error that can occur in C++ program. These are: 1. Syntax errors 2. Logical errors 3. Runtime errors The detail will be discussed later on.

Keywords: the predefined words of the C++ that are used for special purpose in the source program
called keywords. The keywords are also known as reserved words. For example keyword int cant be used as variable name because it is used to define integer type variable. 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. The data is given to the program as input. The data is processed according to the program instructions and output is returned. In C++ each variable is associated with a specific data type. Some basic data types of C++ are: 1. 2. 3. 4. 5. int float double char void

Variables: in any programming language, variables are used to store values during program execution.
A variable represents a location in the computers memory where a value is stored for use of a program. 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. 0000 0001 0002 0003 0004 0005

25

Variable is: i 0002 25

Memory location

Value

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

Anda mungkin juga menyukai