Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » BeginnersRSS Feeds

Tokens, Expressions and Control Structures

Posted By: Mena Schmidt     Category: C++ Programming     Views: 5269

This article explains about Tokens, Expressions and Control Structures in c++.

Tokens and enums

  • The smallest individual element of a program
  • Keywords, identifiers, constants, strings, ops
  • Few more keywords are added to C++
  • Identifiers have arbitrary length in C++
  • Void *ptr1, char *ptr2 then ptr2= ptr1 is valid in c but not in C++, it is ptr2 = (char *) ptr1
  • Enum not required to precede the declaration
  • Anonymous enums are possible with C++ 
  • enums are not global while defined inside class

Derived Data Types & Symbolic Const

  • Array of strings should be including null char
  • Functions are different in more than one way
  • Char * const ptr = “Good” is allowed in C++ (a constant pointer concept!)
  • Int const *ptr2 = &m is a pointer to a constant where content it points to can not be changed
  • Both of above can be used together
  • C++ requires the const to be initialized ( not 0!)
  • A const is local to a file in C++ (static global in c

Important Differences

  • Strict type checking in C++ to enable FO
  • Anywhere declaration of variable
  • Float k = I/j (Dynamic Initialization) is possible
  • A reference variable like float & sum = total is defined than sum and total are interchangeable
  • A reference variable must be initialized at the time of declaration, init is diff than assignment
  • This is an example of operator overloading
  • It can also be used in funs to return values

Operators in C++

  • The scope resolution operator :: to access a global version of the variable 
  • ::* to declare a pointer to a member of a class
  • ->* to access a member using pointer to the object and a pointer to the member
  • Int *p = new int, float *q = new float, check for !
  • Int *p = new int(25) where 25 is initial value
  • Int *p = new int[25] where 25 is the array size
  • Delete p and delete [<optional size>]p

Manipulators & Type Cast Operator

  • Manipulators are operators used to format disp
  • Cout << “this is testing”<< endl (“\n”)
  • Cout << setw(5) << int1 will display the integer in a space of five chars right justified
  • One can define his/her own manipulators 
  • Function like casting is allowed so sum = j + (float) k can also be written as sum = j + float(k)
  • P = int *(q) is illegal but p = (int *) q or typedef int * int_pt and p = int_pt(q) is legal

-  Mixed data in expression is subject to automatic conversion
-  Integral widening conversion is converting a char or short int to int
-  Operator gets new meaning after being overloaded but do not loose their old meaning
-  Operators have precedence which is not changed
-  All control structures, if, if-else, switch, while, do-while, for loop, work the same way

  
Share: 

 
 
 

Didn't find what you were looking for? Find more on Tokens, Expressions and Control Structures Or get search suggestion and latest updates.

Mena Schmidt
Mena Schmidt author of Tokens, Expressions and Control Structures is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!