Demonstrate the difference between prefix postfix forms of ++ : Operators : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Operators »

 

Demonstrate the difference between prefix postfix forms of ++









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
/* 
   Demonstrate the difference between prefix 
   postfix forms of ++. 
*/ 
using System; 
 
public class PrePostDemo {  
  public static void Main() {    
    int x, y; 
    int i; 
 
    x = 1; 
    Console.WriteLine("Series generated using y = x + x++;"); 
    for(i = 0; i < 10; i++) { 
 
      y = x + x++; // postfix ++ 
 
      Console.WriteLine(y + " "); 
    } 
    Console.WriteLine(); 
 
    x = 1; 
    Console.WriteLine("Series generated using y = x + ++x;"); 
    for(i = 0; i < 10; i++) { 
 
      y = x + ++x; // prefix ++ 
 
      Console.WriteLine(y + " "); 
    } 
    Console.WriteLine(); 
    
  } 
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Operators