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();
}
}
Related examples in the same category