Basics of C++.

C++ CHARACTER SET

Character set is a set of valid characters that a language can recognise. A character represents any letter, digit, or any sign. The C++ has the following character set:

  • Letters : A-Z, a-z
  • Digits : 0-9
  • Special Symbols : Space + - ∗ ⁄ ^ \ ( ) [ ] { } = != < > . ′ ″ $ , ; : % ! & _ # <= >= @
  • White Spaces : Blank space, Horizontal tab (→), Carriage return (↵), Newline, Form feed
  • Other Characters : C++ can process any of the 256 ASCII characters as data or as literals.

TOKENS (LEXICAL UNITS)

In a passage of text, individual words and punctuation marks are called tokens or lexical units or lexical elements. C++ has the following tokens:
  • Keywords
  • Identifiers
  • Literals 
  • Punctuators
  • Operators

1. Keywords


The keywords are the reserved terms in any programming language. Every keyword in the language is expected to provide an intended functionality to the program. We cannot use the keywords  as variable names because this practice tries to assign a new meaning to the keyword which is not appreciated nor allowed in any programming language. However, the C/C++ pre-processor directives (so-called header files) can be used to specify text to be exchanged for keywords before compilation. C language preferably supports for 32 keywords that we have mentioned in the tabular form below:
Some keywords of c++.

2. Identifiers


Identifiers are fundamental building blocks of a program and are used as the general terminology for the names given to different parts of the program viz. variables, objects, classes, functions, arrays etc. Identifier forming rule of C++ has been specified in the adjacent box.

Even though original C++ considers all the characters, (in an identifier) significant yet it is implementation dependent. It varies from one version to another.

C++ is case sensitive as it treats upper an lower-case characters differently.

There are some rules while defining an identifiers:-

i) The first character of identifier should be an alphabet or underscore. The rest can be letters or digits or underscore.
ii) Special characters except underscore can’t be part of identifiers.
iii) Keywords can’t be used as identifiers however keywords written in uppercase form can be used as identifiers.
iv) Lower case and upper case letters are distinct.
v) Maximum length of an identifier can be of 31 characters. However the length varies from one version of compiler to another version.
  • Some valid examples:- sum, a1, a2, _1, _a, average, a_b, x123y...
  • Some invalid examples:- 1a, a-b, float.

3. Literals


The constant values used in c++ are known as literals, there are four type of literals namely.

i) Integer constant:- A value written without fraction part is known as integer constant. Example: 25, -674, 0 etc.
ii) Floating constant:- A value written with fraction part is floating value. Value of this type can be written with or without exponent form. Example: 2.34, -9.2154, 1.21E10
iii) Character constant:- A single character written within single quotation marks is known as character constant. Example: ‘g’, ‘9’, ‘$’ etc
iv) String constant:- It is an array of characters enclosed in double quotation marks. Example: “Shubham”, “03-aug-2009”. Double quotation mark is a delimiter which determines length of a string.
v) Bool literal:- the bool literal in C++ is used to represent one of the two boolean values i.e., true (boolean true) or false (boolean false). Internally boolean true has value of 1 and boolean false has value of 0.

4. Punctuators


The special symbols being used with context to programming language are illustrated below as:

Brackets []: These opening and closing brackets are used as array element reference. These are used to indicate single & multidimensional subscripts.
Braces {}: Opening and closing curly braces are used to mark start and end of a block of code containing more than one statement.
Comma ( , ): To separate more than one statement, Comma is used for example in for loop comma separates initialization, condition & increment.
Semicolon ( ; ): Used at the end of statements for termination.
Parenthesis () : Are used to indicate function parameters & function calls.
Asterick ( * ): This special symbol is used to create a pointer variable.
Assignment Operator ( = ): For assigning values, this special symbol is used.
Preprocessor ( # ): This you must have seen attached with the header files. This is automatically used by the compiler to transform your program before actual compilation.

5. Operators


The operators are the symbols that are commonly used to trigger some action when applied to variables or other objects. The operator needs some data items to act upon, those data items are referred to as Operands. For example in (a + b), ‘+’ sign is the operator whereas ‘a’ & ‘b’ are the operands.

Types of Operators

Unary Operators: The operators that work upon a single operand only are called Unary Operators. Example:- Increment & decrement operators.

Binary Operators: As clear from its name itself, Binary Operators are those which require two different operands to work upon. They can be classified into:
Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
Conditional Operators
Bitwise Operators
Binary operators


Ternary Operators: The operators that require three different operands to work upon are known as Ternary Operators. Conditional Operator (?:) is an example of ternary operator.

You may also like to visit:-





Post a Comment

0 Comments