this post was submitted on 23 Oct 2021
1 points (100.0% liked)

C & C++

59 readers
1 users here now

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 0 points 2 years ago (4 children)

yes but sum() gives the value 90 in the main function. Why is that?

[–] [email protected] 0 points 2 years ago (3 children)

You're printing s to console not returning it.

[–] [email protected] 0 points 2 years ago (2 children)

Oh... so cout << and return don't mean the same thing.

[–] [email protected] 1 points 2 years ago (1 children)

don't know if you are a beginner to programming in general or c/c++ specifically but it's better to start with c before c++, it's simpler and clearer (than c++) to a beginner

then cout syntax is absolutely horrible and very misleading, use c's printf or, if you can, use fmt, it's super fast and even simpler than c's printf

[–] [email protected] 2 points 1 year ago

If you want to learn C++, you should start with C++. Starting with C will form unsafe habits and teach unsafe paradigms that have been replaced by language features or parts of the C++ standard library

it's simpler and clearer (than c++) to a beginner

A language only seems as clear as the tutorial used to teach it. If you think the basics of C++ can be better taught using a C tutorial,. you've been looking at the wrong C++ tutorials. Transitioning from C to C++ will be a confusing process for a beginner