Jump to content
  • Advertisement
Sign in to follow this  
ncasebee

Code Snippet from Book, I don't get.

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

inline void BoundsCheck (int &a)
{
if (a < 5) a = 5;
if (a > 10) a = 10;
}

void Foo(void)
{
int a = 0;
BoundsCheck(++a);
cout << a << "\n"
}




The book, Special Effects Game Programming with Direct X says the printout should be 1. I say it should print 5. I tested it in my own code, and sure enough it printed 5. What gives? My code....
#include <iostream>
using namespace std;

inline void BoundsCheck(int &a)
{
	if (a < 5) a=5;
	

	if (a > 10) a=10;
	
}


int main ()

{
	int a = 0;
	BoundsCheck(++a);
	cout << a << "\n";

	return 0;

}

Share this post


Link to post
Share on other sites
Advertisement
You're right it should be 5.
Maybe they were referring to the line that says
BoundsCheck(++a);
, explaining that a is now 1.

Share this post


Link to post
Share on other sites
But still the printout would read 5......I don't know what they were talking about. The snippet comes from Mason McCuskey's "Special Effects Game Programming with DirectX."

I don't know.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!