NWN2 Scripting.




Simulation Training.

Introduction
Home
First Program
Seeing Results
Variables and Data Types
Comments
Functions
Data Conversion
Random Numbers
Concatenation
Arithmetic Operators
Compound Assignments
One More or Less
Precedence
Relational Operators
The Open Branch
The Closed Branch
Logical AND
Logical OR
Compound Statements
ELSE If
Switch Case
The ? Operator
The for Loop
The while Loop
The do while Loop
Introduction to Functions
Passing Values
Passing Multiple Values
Multiple Functions
Simplifying Functions
TRUE/fALSE Conditions
Return Values
Setting Global Variables
Getting Global Variables
Setting Local Variables
Getting Local Variables
WayPoints Introduction
Static Waypoint Sets
Dynamic Waypoint Sets
Dynamic WP Cycles
Input Output

One More or Less

  It is very common in programming languages to increase or decrease the value of
a variable by just one. C++ has a very special and easy way of doing this. This
section demonstrates what that is.


 The ++ and -- Operators

The following example shows the ++ and -- operators used in a program.

void main( )
{
int V = 5;

  V++;  // Post increment (increase by 1 after use).
   ++V;  // Pre increment (increase by 1 before use).
   V--;  // Post decrement (decrease by 1 after use).
    --V;  // Pre decrement. (decrease by 1 before use).
}


An analysis of the above program yields:

  •     One variable was declared and assigned a value of 5.
  •    V++ caused the assigned value of the variable to increase by one after  it is used by the program giving it a new value of 6.
  •    ++V caused the assigned value of the variable to increase by one just before it is used by the program giving it a new value of 6.
  •    V-- caused the assigned value of the variable to decrease by one after it is used by the program giving it a new value of 4.
  •    --V caused the assigned value of the variable to decrease by one just before it is used by the program giving it a new value of 4.

 


Standard Increment and Decrement Operators

The table below lists the standard arithmetic operators and their meaning.

Meaning Code Result
Post-Increment Operator  X++ Increment after use
Pre-Increment Operator ++X Increment before use
Post-Decrement Operator   X-- Decrement after use
Pre-Decrement Operator   --X  Decrement before use


You can now understand the reason for the name C++. It is at least one better than the programming language called C.


Nwn2Scripting provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 2008 by Adamson House, Ltd. All Rights Reserved.

Questions or Comments: EMail Webmaster

Donations are to Adamson House, Ltd who maintains this site.
All donations go the the improvement of this site.