CS253

CS253: Software Development with C++

Fall 2011

Example Increment

Post-Increment

This example is bad. Don’t do this:

#include <iostream>
using namespace std;

int main() {
   int n = 1;
   cout << ++n * ++n << endl;
}

Don’t do this, either:

#include <iostream>
using namespace std;

int main() {
   short nums[] = {1, 2, 3, 4};

   short *p = nums;
   cout << *p++ << ' ';
   cout << *p++ << '\n';

   p = nums;
   cout << *p++ << ' ' << *p++ << '\n';
}

Modified: 2010-09-09T22:09

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building