Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!


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.