Jump to content

Can someone help me on functions in c++ :(

Featured Replies

You'll need to be a bit more specific than that :)

What exactly are you having trouble with? Do you have an example?

What are you asking, I know java, so it might not be the same for c++, but a function could be 8+4, if maybe you are trying to make a math application, or are you asking about something defining a function?

I'm going to have to do some research in it.

  • 4 years later...

A function is a way to encapsulate a block of code. Say you have to do some computation multiple times. Instead of repeating the code that does the computation multiple times, you enclose that code in a function, and call the function every time you need to do the computation. A big advantage of this is that if you need to modify the computation code, you only need to do that in one place.

Another important use for functions is to decompose other long functions. Say you have a function where you first do A, then B, and then C. It is a good idea to separate the code that does A into a function, the code that does B into another function, and the code that does C into yet another function. Then you have your function just call those three functions. This makes it much easier to read and maintain you code.

Edited by Binary Tree

  • 1 year later...
  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.