Friday 8 February 2013

Basics Of C++

C++ Character Set



These are set of valid character which compiler understands.

LettersA-Z, a-z
Digits0-9
Special CharactersSpace  +  -  *  /  ^  \  ()  []  {}  =  !=  <>  ‘  “  $  ,  ;  :  %  !  & ? _  #  <=  >=  @ 
Formatting charactersbackspace, horizontal tab, vertical tab, form feed, and carriage return

I would suggest to write the full source code in small characters.

Tokens

Tokens are the group of characters which are logically belong together.The Programmer ( one who writes the program ) can write the source code using these tokens. C++ uses these type of tokens :

Keywords, Identifier, Literals, Punctuators, Operators.

1. Keyword

Keywords are the reserved words in C++ which have predefined meanings to compiler.The most common keywords are given below

asmautobreakcasecatch
charclassconstcontinuedefault
deletedodoubleelseenum
externinlineintfloatfor
friendgotoiflongnew
operatorprivateprotectedpublicregister
returnshortsignedsizeofstatic
structswitchtemplatethisTry
typedefunionunsignedvirtualvoid
volatilewhile

2. Identifiers

Symbolic names can be used in C++ program. A programmed uses these symbolic names for giving a particular value to it or for any other use. For example Vivek = Yuvraj .. In it vivek is an Identifier having some value.

These symbolic names (eg. Vivek ) are  called Identifiers.

There are some rules for creating an Identifier.

  • An Identifier can consist of Alphabet, Digits, or underscore "_"
  • Identifier must not start with a digit.
  • C++ is case sensitive ie. Upper case and Lower case words have different meaning. That's why i told you to use lower case for writing a source code.
  • It should not be a reserved word.

3. Literals

Literals are the data items whose value does not change from the starting of the program till it's execution.
The following types of Literals are there in C++ Compiler.

  • Integer Constants
  • Character Constants
  • Floating Constants
  • String Literals

 Integer Constant

     Integer Constant are whole number with no Fraction Part. C++ allows three types of Integer Constants.
     Decimal Integer Constant : It consist of sequence of digits like any ordinary number , but it should not 
                                                   start with a Zero ( 0 ) . Some Examples. :-  111,444,12314, -87

     Octal Integer Constant     : It consist of sequence of  digits starting with Zero. Eg. 041,054

      Hexadecimal Integer Constant : It consist of sequence of digits proceeded by ox and OX.


Character Constant

A character constant in C++ must contain one or more characters and must be enclose within brackets. For Example 'A' , '9' etc. C++ also allows non graphic characters ,these are the characters which can be typed directly by Keyboard, Example :- Backspace, Tab , Home etc.These characters can be represented by an escape sequence. An escape sequence represents a single character.The following table gives a listing of common escape sequences.

Escape SequenceNongraphic Character
\aBell (beep)
\nNewline
\rCarriage Return
\tHorizontal tab
\0Null Character

Floating Constants
Floating Constants are also called real constants. They are the number which have fractional Parts. They can be written in Fractional Form. In other words these are the constants which can store the value of a Decimal number. Example :- 4.5666  ,  5.4 etc.

String Literals

These are the sequence of characters enclosed within double quotes is called a string literal .String literal is automatically added with a special character '\0' which donates the end of a string. As a result size of a string in C++ is 1 more than the actual length. For Example :- Word " Facebook " has total 8 characters but in computer memory it will be represented by " Facebook\0 " , Now in computer memory it has total 9 Characters. 

1 more example is taken. Word " Lappy " has total 5 characters. Now without thinking add 1 to it and it becomes 6. Hence in computer memory word Lappy has 6 characters.

4. Punctuators

These characters are used as Punctuators in C++

Brackets [   ]Opening and closing brackets indicate single and multidimensional array subscript.
Parentheses (   )Opening and closing brackets indicate functions calls,; function parameters for grouping expressions etc.
Braces {   }Opening and closing braces indicate the start and end of a compound statement.
Comma ,It is used as a separator in a function argument list.
Semicolon ;It is used as a statement terminator.
Colon :It indicates a labeled statement or conditional operator symbol.
Asterisk *It is used in pointer declaration or as multiplication operator.
Equal sign =It is used as an assignment operator.
Pound sign #It is used as pre-processor directive.


5. Operators

Operators are the special symbols used for special purposes. There are many Operators available in C++ , but i have written the most common operators below :-

  1. Arithmetical Operator
  2. Relational Operator
  3. Logical Operators.
  4. Unary Operators
  5. Assignment Operators
  6. Conditional Operators
  7. Comma Operator







0 comments: