Terms used in C++


Before providing a technical explanation a compiler in layman’s language is a program which will read through the C++ program code (code refers to the program written by the programmer) line by line. The compiler will read each and every character that has been typed in the program code. After reading the entire code, the compiler will convert the code into machine level format (i.e. 0s and 1s). The compiler is very dedicated and hard working since it will meticulously read each and every character.

Technically speaking, the microprocessor in a computer can understand only binary numbers (only 0s and 1s). It is not possible for us to write programs in binary numbers. Compilers will convert the coding for a program into machine understandable form (i.e. it will convert the instructions we type into machine understandable form). The instructions we type (in something similar to English), is known as the source code. The compiler converts the source code into the object code (which the microprocessor understands and we cannot understand). There is a detailed discussion on this topic in the chapter “Advanced Topics”.

If you are new to programming you might wonder as to where you should type your C++ program?
First of all you should have a C++ compiler. There are many compilers available for free on the Net and they can be downloaded from the Net. After downloading the compiler, create a new C++ source file and type the C++ code in the compiler. Later on in this book, we shall see how to run a C++ program in the compiler.

A few compilers available on the Net are :

  1. Borland C++ compiler : www.borland.com/bcppbuilder/freecompiler/

  2. Bloodshed Dev C++ compiler : www.bloodshed.net/devcpp.html

  3. DJGPP C++ compiler

  4. For Linux/Unix the GNU C++ compiler is available in standard installations of the operating system.

Most compilers nowadays provide an Integrated Development Environment (IDE), i.e. they have an editor, a compiler, a linker and some extra tools (like a debugger). In schools and colleges the most commonly used compiler is Turbo C++. Most of the programs written in this book are compatible with Turbo C++. It is better to use Visual C++ because advanced features like namespaces and exception handling are not available in older versions of Turbo C++. All compilers will support the basic features of C++.

If you are using Linux/Unix then you will be having the GNU C++ compiler in your Linux distribution CD (this compiler is freeware but it doesn’t have a graphical user interface- it can only be used from the command line; refer to the Appendix section).


Keyword is a word that the compiler already knows, i.e. when the compiler sees a keyword somewhere in the program it knows what to do automatically.

For example, when the compiler encounters the keyword ‘int’, it knows that ‘int’ stands for an integer. Or if the compiler reads a ‘break’, then it knows that it should break out of the current loop.


As the name suggests, a variable is something whose value can be changed throughout the program. It is not fixed. On the other hand, a constant is one whose value remains the same (constant) throughout the program.


Operator is something that performs operation on a variable. For example + is an operator that performs the addition operation. The terms on which the operator operates are known as the operands. In the expression

x + y

x and y are known as the operands and + is the operator.


Expression performs an operation and consists of operators and operands (or variables).
a>b
This is an expression in which a and b are the operands. > is the operator.


Binary means ‘two’ and ‘unary’ means one. A binary operator operates on two operands (or two values) whereas a unary operator operates on just one operand.


In C++ these two terms are used frequently. Declaration of a variable means telling the compiler that this variable is an integer, or this variable is a character. A declaration will inform the compiler about the type of a variable. Defining a variable means allocation of memory space by the compiler for that particular variable.

In the case of variables, a single statement performs both declaration and definition. For example: the statement

int x;

declares and defines ‘x’ as an integer.

Remember that declaration is just declaring the type of something (telling the compiler what data type it belongs to) but definition means allotting space to it. It may seem as if both are one and the same; in many cases they are but in a few places they are not (these cases will be dealt with later).


Initialization refers to the first (initial) assignment of a value to a variable.
x = 50;
This initializes the value of x to 50.
Always remember that the value to the right of the equal sign will be assigned (or stored) to the value on the left of the equal sign.

For example:

a = b;

This means that value of b is assigned to a.


There are different type of brackets:

All of these brackets are used in C++ but each one is used for different purposes.


Characters include alphabets, numbers and other special symbols as well (like *, /, - etc…). Usually one tends to think of characters as only alphabets; but remember a character could be anything (an alphabet, a number, a special symbol on your keyboard or even a blank white space is a character).


                    Every language has its own ‘syntax’. By the term syntax we refer to the structure of a language and use of correct language. English has its own set of rules while French has slightly different rules. The vocabularies of both the languages are also different. Programming is also another language (that’s it is called programming language). Just like any other language it has its own set of rules that must be complied with. This is known as the syntax. Only if the programmer adheres to the syntax will the compiler understand the instructions.


                    This is a very common term in programming languages. In fact it is very common to hear someone say, "Syntax Error". Error means a mistake and syntax error means that there is a mistake in the syntax. The compiler reads the entire program before execution. While reading the program, if the compiler discovers that it can’t understand some instruction it will display an error message. Till the error is cleared, the program cannot be executed. The compiler will give a syntax error if the syntax has not been adhered to properly. Errors generated by the compiler are known as compile-time errors.

There are other types of errors as well. The compiler is not intelligent to detect all types of errors. For instance if the programmer make a logical error, the compiler will never know it. Suppose a program is written for adding two numbers and in the coding, instead of the + operator, the – operator has been used. The compiler will not recognize any error during compilation and the program will execute (but the programmer will not get the desired output). This is a logical error and as a programmer you have to be very careful while coding. The compiler is not brilliant enough to know what is in the programmer’s mind!


    Executing refers to the process of running a program. We’ve talked about object file, but can we execute object files directly? The compiler produces an object code but this object code generally depends on some other external files. For example: if you are using complex mathematical functions, you might make use of functions which have been defined by some other programmer. That programmer would have created a library which you can include in your source code (instead of creating those functions in your program). A library is a collection of object files. Thus your program will actually depend on the other object files for some of the complex mathematical functions which you’ve used. Someone now has to link up all these object files to produce an executable file. This work is done by the ‘linker’. Most modern compilers have a linker included in them. Linkers are discussed in detail later.

Remember: Each C++ source code needs to be compiled separately to produce an object code (ten source codes mean that we’ll have ten object codes). Finally the linker has to combine these ten object codes to produce one single executable module.


is the process of troubleshooting a program (of course it’s done when the program doesn’t work up to your expectation!). Debugging is the process of identifying bugs in the code. A bug is a programming term for an ‘error’.


Some extra details: 

An interesting point (about Kilo, Mega etc.): 

You might have read that 1Kilobyte = 1024 bytes and perhaps you thought about it as well, “Shouldn’t 1Kilobyte = 1000 bytes?” 

Let’s start with our familiar decimal system. In the decimal system, 1 Kilo unit = 1000 units.

For example:

This is fine as far as the decimal system is concerned. Here the base used is 10 and we express everything in powers of 10.

Computers speak in binary language and the base used here is 2. Let’s extend the concept of ‘kilo’ to the binary system.

Can we represent the value 1000 as a power of 2? Let’s try: 

Power

Value

20

0

21

2

22

4

23

8

24

16

25

32

26

64

27

128

28

256

29

512

210

1024

Oops! We’ve just exceeded 1000 in 210. In the binary system, the closest we come to 1000 is 1024. Thus 1 Kilobyte = 1024 bytes (but for rough calculations we assume it as 1000 bytes).


Recap of the First Unit:

¤       Computers only understand binary language (1s and 0s).

¤       8 bits form a byte.

¤       The different types of storage are: internal CPU registers, RAM, ROM and secondary storage.

¤       RAM is used as main memory and data is present only as long as the computer is switched on.

¤       Main memory is directly accessible by the computer whereas secondary memory is not.

¤       During execution programs should be present in the main memory.

¤       Word-size of a machine depends on the size of the processor’s internal registers.

¤       Machine level language is written in 1s and 0s.

¤       Assembly level languages make use of mnemonics (mnemonics are abbreviated English words used to represent instructions).

¤       High level languages like BASIC are in simple English but they are far away from the real hardware of the system.

¤       C has the advantages of both high level and low level languages. But it doesn’t support Object Oriented Programming (OOP).

¤       C++ is actually C with classes (i.e. it supports OOP).

¤       A compiler is required to convert the source code (i.e. the instructions we type in English) into the object code (i.e. the machine language which the computer understands).

¤       1 kilobyte = 1024 bytes (and not 1000 bytes).


Go back to the Contents Page


Copyright © 2005 Sethu Subramanian All rights reserved. Sign my guestbook.