Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
#include <iostream> #include <string> // Overloaded print functions void print(int value) { std::cout << "int: " << value << " "; } void print(double value) { std::cout << "double: " << value << " "; } void print(const std::string& value) { std::cout << "string: " << value << " "; } // Default arguments — defaults only in declaration void connect(const std::string& host, int port = 443, bool secure = true) { std::cout << (secure ? "https" : "http") << "://" << host << ":" << port << " "; } // Inline helper inline int square(int n) { return n * n; } int main() { print(42); print(3.14); print(std::string("overload")); connect("example.com"); // uses defaults connect("example.com", 8080); // overrides port connect("example.com", 80, false); // overrides both std::cout << "square(7) = " << square(7) << " "; return 0; }
Result
Open