Basic Terms In C++

Basic Terms In C++

    On this page we are going to check out some very basic terminology for the beginners of C++. These terms are often used in programming. So here we go :-)
Variables : As the name suggest, values of a variable may vary from time to time within a program. These variables are stored in memory of our computer (RAM) and can be used to store data of any kind we wish to. Lets have a geek definition of a variable which we can use to impress our teachers:
"A variable is a way of referring to a memory location used in a computer program to hold important data comprising of simple numbers, alphabets, symbols, and numbers with decimal values."
While making a program we can choose any name for our variable just by giving little attention to the following rules:
  • We can only declare a variable with a maximum name length of 32 characters.
Well, our first rule has got exception because the maximum length for name of any variable depend on compiler to compiler. But still If you follow this rule, it will only help you because long variables only results in typing efforts and taking away our precious time. Now lets roll on to our next rules.
  • The first character of any variable can be either an alphabet or an underscore( _ ).
  • No two variables can have same name in the same scope.
For the above rule, there is a little thing that we need to know. Small letters and capital letters are treated differently by computer. This is what we call case sensitivity. So the variable names pet, Pet, pEt, peT, PeT and PET all different variables instead of one.
  • Commas or spaces are not allowed to be used in variable names.
This Stinks!! We cannot use a space!!! What if we want to use a variable name like "my cute pet"? For the solution of this question there is a general trend of using an underscore( _ ) instead of a space. So the variable name can be declared as "my_cute_pet".
  • Except underscore no special symbols can be used while naming a variable.
  • A keyword cannot be used as  a variable name .
I know it feels a little bore to remind all the rules while declaring any variable and check whether or not its satisfying all the rule, but trust me once you start programming, you'll get used to it.
Keywords : These are some words whose meaning are already known to a compiler (in broad sense to a computer).So of course its understood that we cannot define a word which is already defined. And that is what our last rule is trying to tell.

Comments : These are the part of the code that make no sense to compiler. That means if comments are encountered, compiler simply skips them and starts reading the next part of the code, no matter what is written in it. These are generally used to tell
which part of code is designed to do what function to the reader of program and it has nothing to do with compiler. Comments are also known as code tags or simply tags. There are two types of tags in C++ :
  • Multi line comments: These comments are also called C style comments. We can cover any number of lines under their scope. The syntax for using C style comment is as follows....
    /*  comments line 1
    comment line 2
    ...........
    ...........
    comment line n */

  • Single line comments: These comments are also called C++ style comments. We can only cover a single line of code under their scope. They start with double slashes(//) followed by whatever is to be written in comments. So the syntax is
    //Comment covering only 1 line
We will not discuss a lot about comments as we will see how they work in our programs later. For now the given information is sufficient.
Written by T-Rex
<< History of C++                        Programming-Gum Home              Decision Making>>

No comments:

Post a Comment