Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Fundamentals of C Operators & Expressions

Wich is a compact division the Quizz No. 5?

I intented 3 forms of the division learninf from the video and my result is wrong ...

2 Answers

Andrew Pope
Andrew Pope
11,915 Points

Hi Erick!

Say we had the value 3 assigned to an integer variable called a. Now we want to add 4 on to a. We could do it like this:

int a = 3;
a = a + 4;  // This is one way to add 4 to the integer variable a.

This is fine, however we can do it slightly differently and make our code more compact.

int a = 3;
a += 4; // This is the compact way of doing it.

In C/C++/Objective-C, the basic mathematical operators have their own compact notation, for example.

a += 3;  // This is the compact form of a = a + 3
a -= 3;  // This is the compact form of a = a - 3
a *= 3;  // This is the compact form of a = a * 3

and finally (although I'm sure you have guessed it already!),

a /= 3; // This is the compact form of a = a/3  (So the compact form of division)

Basically, it's a way of saying "Hey, divide a by 3, then make sure that a is set to this new value".

I hope this helps!

Andy.

Hi Andy

I'm newbie in the concepts of C ... and TreeHouse is the best solution for learning in this area, Thanks you very much for the response.and the help.

Erick