Lesson 7 of 24

Functions, Default Arguments and Overloading

9 min 25 XP

C++ lets several functions share a name as long as their parameters differ (overloading). Default arguments make trailing parameters optional.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

Challenge

+25 XP

Write bool isPrime(int n). In main(), read n and print every prime from 2 to n separated by spaces. Input: 20 → Output: 2 3 5 7 11 13 17 19

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.