Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Hidden operators and values

Node:Hidden operators and values, Next:, Previous:Advanced operators, Up:Advanced operators



Hidden operators and values

Many operators in C are more versatile than they appear to be at first glance. Take, for example, the following operators:

  • =
  • ++
  • --
  • +=
  • -=

These operators can be used in some surprising ways to make C source code elegant and compact. (See Expressions and operators, if you need a refresher in what they do.) All of them can form expressions that have their own values. Such an expression can be taken as a whole (a "black box") and treated as a single value, which can then be assigned and compared to other expressions, in effect, "hidden" within another expression.

The value of an expression is the result of the operation carried out in the expression. Increment and decrement statements have a value that is one greater than or one less than the value of the variable they act upon, respectively.

Consider the following two statements:

c = 5;
c++;

The expression c++ in the above context has the value 6.

Now consider these statements:

c = 5;
c--;

The expression c-- in the above context has the value 4.

 
 
  Published under free license. Design by Interspire