Tokens of C++ language

In C++ language we use alphabets, numbers, special symbols, operators etc to form different words which has specific meaning and significance.These meaningful words are called tokens. C++ language tokens are used to create a sentence/statement and sentences/statements are used to create a program.
In other words, "A token is a smallest individual unit of any programming language." 
C++ लैंग्वेज में हम अल्फाबेट, नंबर, स्पेशल सिंबल एवं ऑपरेटर इत्यादि का प्रयोग कर शब्द का निर्माण करते है, इन शब्दों का एक निश्चित अर्थ एवं महत्त्व होता है। इन्ही अर्थयुक्त\शब्दों को टोकन कहा जाता है। C++ लैंग्वेज टोकन की सहायता से वाक्य निर्मित किया जाते है एवं वाक्यों के समूह से प्रोग्राम तैयार होता है। 
अन्य शब्दों में ,"एक टोकन किसी प्रोग्रामिंग लैंग्वेज की सबसे न्यूनतम व्यक्तिगत इकाई होती है। "  

Following tokens are used in C++ language :-
C++ लैंग्वेज में प्रयुक्त किये जाने वाले टोकन निम्न है -

1.) Keyword-  
A keyword is a special word of a programming language which has previously defined fixed meaning and programmer will not allow to make change in it . Keyword is also known as " reserve word" of C++ language. Each keyword has its specific work and written in small letters of English language.
एक कीवर्ड, किसी प्रोग्रामिंग लैंग्वेज का एक विशेष शब्द होता है जिसका पूर्व निर्धारित अर्थ होता है एवं प्रोग्रामर द्वारा इसमें परिवर्तन नहीं किया जा सकता है। की वर्ड को रिज़र्व वर्ड भी कहा जाता है। प्रत्येक कीवर्ड का एक निश्चित कार्य होता है एवं इसे सदैव अंग्रेजी भाषा के छोटे अक्षरों में लिखा जाता है।
Keywords of C++- 
operator,new,public,class,asm,template,
this,private,protected,friend,throw,catch,
try,virtual,inline,delete. 

In addition, C++ also supports all other keywords of c language.
इसके अतिरिक्त C++ , C लैंग्वेज के सभी कीवर्ड्स का समर्थन करती है।   

2.) Identifier- 
An Identifier is a logical name provided to a memory location. Identifiers are the names given to various program elements such as variables, symbolic constants, functions, array , structure , union , pointer , enumeration , files etc. Compiler can identify them using identifier because C++ language is a case sensitive language .
एक आइडेंटिफायर एक लॉजिकल नाम होता है जो किसी मेमोरी लोकेशन को प्रदान किया जाता है, ये विभिन्न प्रोग्राम अवयव जैसे वेरिएबल,सिंबॉलिक कांस्टेंट, फंक्शन,अरे,स्ट्रक्चर, यूनियन, पॉइंटर,एनुमेरेशन, फाइल इत्यादि को प्रदान किये गए नाम होते है जिनसे कम्पाइलर इनकी पहचान करता है। C++ लैंग्वेज एक केस सेंसिटिव लैंग्वेज है। 
Following rules must be satisfied when the name of variable/identifier is prepared by user:-
वेरिएबल/आइडेंटिफायर का नामकरण करते समय निम्न नियमो का पालन किया जाता है -
The name of variable / identifier must start with an alphabet . It can be alphabets or alphanumeric values.
वेरिएबल/आइडेंटिफायर का नाम अल्फाबेट से प्रारंभ होना चाहिए। यह नाम अल्फाबेट या अल्फानुमेरिक हो सकता है।
The name of variable / identifier should not be greater then 255 letters.
वेरिएबल/आइडेंटिफायर का नाम 255 अक्षरों से अधिक नहीं होना चाहिए।
The name of variable / identifier must not similar to any keyword of C language. 
वेरिएबल/आइडेंटिफायर का नाम कीवर्ड नहीं होना चाहिए।
The name of the variable / identifier should  be relevant to the subject. 
वेरिएबल/आइडेंटिफायर का नाम विषय से सम्बंधित होना चाहिए।
There should not be any blank space or any specific symbol between the name of the variable / identifier except underscore( _ ).
वेरिएबल/आइडेंटिफायर नाम के मध्य कोई रिक्त स्थान या विशेष चिन्ह का पयोग नहीं किया जाना चाहिए। ( अंडरस्कोर _ को छोड़कर )

Example-
1.) legal identifiers (उचित आइडेंटिफायर) :-
float _number;
float a123;
int simple_interest;

2.) illegal identifiers (अनुचित आइडेंटिफायर):-
float :x;
float for;
int max marks;
float 7g;

3.) Constants- 
Constants are special quantities of program which refers fixed values and its value can not be changed during program execution. Constants are known as 'Literals' also. 'const' keyword is used to prepare constants of C language and user can also use #define directive for creating universal constants/ macros.
कांस्टेंट वे विशेष राशियाँ होती है जिनके द्वारा एक निश्चित मान को रखा जाता है एवं प्रोग्राम एक्सीक्यूशन के दौरान इन मानों में परिवर्तन नहीं किया जा सकता है। कांस्टेंट को लिटरल भी कहा जाता है। कांस्टेंट तैयार करने के लिए const कीवर्ड का प्रयोग किया जाता है एवं यूजर #define डायरेक्टिव का प्रयोग कर ग्लोबल कांस्टेंट/ मैक्रो तैयार कर सकता है।
Syntax:-
const constant_name=value;

Example:- 
123- Integer constant
203.45-floating point constant
‘A’- character constant
"Raja"- string constant
‘\n’-backslash constant
‘ox2’- hexadecimal constant
‘o37’- octal constant
L’ab’- wide character constant

String- 

In c++ language, string is represented in two ways.

1) C language style string - char s[10]=”Lovekush” ;
2) C++ string class string- String s = “Lovekush”;

Operators- C++ language is a superset of operators in which all operators of c language are included. It defines also some new operators.
Ex- << - Insertion operator
      >> - Extraction operator
      :: - Scope resolution
new, delete – Dynamic memory allocation, dislocation operator.

Initialization and Declaration of variables in c++ language –
          In c++ language, declaration and initialization of variables is performed at any statement of program. We can use variables in below statements whereas in c language, user has to declare and initialize variable before executable statement. So, user can create or define variables before or after or in executable statement.
Syntax – datatype variable_name1, variable_name2,_ _ _variable_name n ;
Local variable – Those variables which are created in any block of program are called local variables. Generally, these variables are of automatic storage class. It means their scope and life is local to the block. When program control shifted outside the block then variables destroy automatically. Local variables are directly accessible in any statement of program.
Global variable – Those variables which are created independently outside from all the block of program are known as global variable. Generally, these variables are of extern storage class. So, scope and life of this variable is global. It means their existence remains unchanged during the execution of program. In c++ language, scope resolution is used to access global variables. With the help of global variables program will be easy, summarized and effective.
Ex- A c++ program for calculation of simple interest.
#include<iostream.h>
#include<conio.h>
Float si; // global variable
Void main() {
Void display() ;
Float p,r,t ;
Cout<<”Enter principle, rate, time”<<endl ;
Cin>> p>> r>> t; // local variable
:: si= (p*r*t)/100 ;
Display () ;
}
Void display () {
Cout <<”simple interest =”<< :: si << endl ;
}
In above ex, p, r, t are the local variables and which are accessible only in main function but si is global variable which is used in main function as well as display function with the help of scope resolution operator.

No comments:

Post a Comment