• tmpod@lemmy.pt
    link
    fedilink
    arrow-up
    5
    ·
    3 years ago

    No. Printing something to the console (pushing something to cout with the << operator) is not the same as returning a value.

    Think of returns like what you have in math. When you have a function, let’s say

    int double(int n) {
        return 2 * n;
    }
    

    that returns an int, calling it will “replace” the expression with its result, much like in math. So in this instance, doing 3 + double(2) would be like doing 3 + 4. Math is the same way; if you have a function, f(x) = 2x, doing 3 + f(2) would be the same as doing 3 + 4.

    Printing to the console involves doing I/O (input/output), and actually writing a string to a file, which then the terminal can display.