Search This Blog

Sunday 26 January 2014

Some Basic Concepts

Now that we have seen a C++ program in action, you must be excited and would want to know more about it. But let’s not rush it and start from the beginning. In this post, we will learn various important terms in C++ (and programming, in general), so that when we write a program, we know what we are doing.
·         Compiler: C++ is a compiler based language. A compiler is a software that converts the human-readable  C++ code to machine code that can be understood and executed by the computer. A Compiler is different from an interpreter, which is also used in some languages for the  same task, as it converts the whole source code (the code you write) to object program in one go, and lists the errors, if any, at once. There are many compilers available on the net for C++, the chief being Microsoft Visual C++, Intel C++ Compiler, Borland, and the now obsolete Turbo C++. A list of free C++ compilers can be found here.
·         Tokens: Tokens, by definition, are the smallest individual unit in C++. Tokens are of many types. These are:
1.       Variables/Identifiers: A variable is a portion of memory used to store a value. Each variable is identified by its respective identifier. An identifier is basically a unique name for a variable. There are few rules when it comes to declare valid identifiers:
·         It should begin with a letter. The rest of the identifier can use letters, digits or a sign of underscore.
·         Uppercase and lowercase letters are distinct.
·         Keywords cannot be used as identifiers.
2.       Keywords: These are the reserved words that have some-predefined meaning to the compiler. These keywords can only be used in the way they are defined. The C++ keywords are listed in the table below:
asm
continue
float
new
signed
try
auto
default
for
operator
sizeof
typedef
break
delete
friend
private
static
union
case
do
goto
protected
struct
unsigned
catch
double
if
public
switch
virtual
char
else
inline
register
template
void
class
enum
int
return
this
volatile
const
extern
long
short
throw
while
3.       Operators:          Operators are characters which do some specific task in C++. They are of following types:
·         Arithemetic
·         Relational
·         Logical/Boolean
·         Assignment
·         Increment/Decrement
·         Conditional
·         Comma
·         sizeof
Operators in C++ are an important topic and deserve a post of their own. Hence, I won’t go into details here.
4.       Constants: Constants are the values which never change during program execution. They are also called as literals. Constants can be classified as:
·         Integer Constant: eg. 123
·         Floating point constant: eg 123.45
·         Character constant: eg ‘a’
·         String Constant: eg “C++”
Constants would also be discussed in detail in another post very soon.
·         Comments: Comments are the text in the source code that is ignored by the compiler. These are written for the human readers so that they can understand what is happening in a program. Comments are included mainly for debugging purposes. Hence, even though they are not required, it is considered a good programming practise to insert comments in your program. Comments are also of two types:
1.       Single Line Comments: These comments begin with ‘//’(without the quotes). Everything written after // in the line is ignored by the compiler.
2.       Multi Line Comments: These comments begin with ‘/*’ and end with ‘*/’(without the quotes). Everything between those symbols is ignored.

That’s enough for today folks, we will study each of the above mentioned terms in detail in the following posts. Till then, Good bye, Happy Learning!

No comments:

Post a Comment