Functions

Use C++ functions to write more flexible, modular, reusable code.

Start[missing "en.views.course_landing_page.learn-c-plus-plus.course_illustration" translation]
Functions
Lesson 1 of 1
  1. 1

    As a programmer, you will find yourself reusing the same blocks of code over and over throughout your program. In times like these, you can turn to functions. Also known as a method or procedure, …

  2. 2

    C++ comes chock-full of functions that are already created as part of the standard C++ library. But how do you access this hidden hoard of helpful functions? You gain access to various functions by…

  3. 3

    Often, built-in functions aren’t enough to tackle the wide array of programming challenges out there. But never fear: you can write your own functions too! A C++ function is comprised of two disti…

  4. 4

    Let’s build a simple function with no input and no output. We can do that? Enter the […] specifier, which is added in the function declaration before the function name. A […] function, als…

  5. 5

    When you do in fact want your function to return something and pass information back to the rest of your program, C++ has you covered. Just like there are many variable types, there are many differ…

  6. 6

    When functions have a return type other than […] , the function has two new requirements: - There must be a value returned from the function. - The return value must be the same type as the fu…

  7. 7

    Returning data is all well and good, but let’s say you’re visiting NYC and you’ve been told that New Yorkers usually add a 20% tip for restaurants and taxis. It would be really convenient if you co…

  8. 8

    Hang on, you may be thinking, are you limited to one parameter per function? Not at all! You can add as many as you like, but you will have to remember their order when you call the function. [……

  9. 9

    A function with parameters has a couple of requirements: - The function call must include the same number of arguments as there are parameters. - The corresponding arguments must be passed in t…

  10. 10

    Take a look at the program below. We have a […] function named […] and […] with a few statements inside. […] When this program is compiled and executed, […] will print, but [….

  11. 11

    Putting a single function definition above […] is all well and good, but what if you have a whole bunch of functions? With a few functions, you can declare the function above […] and then …

  12. 12

    Wow! Check out all you’ve learned about C++ functions: - A function is a named group of statements that do something together. - Functions allow you to create more flexible, modular, and DRY code. …

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Functions

Start[missing "en.views.course_landing_page.learn-c-plus-plus.course_illustration" translation]