I am learning C++, and I often encounter C++ code that has e.g. printf
instead of std::cout
, and int var[3]
instead of std::array<int,3> var
. I have never learned C, so these just look weird/ugly to me. For some reason, I don't know why, they just stand out as unnatural.
When I go ahead and Google them, they often show up as "C string, C array, C ...". I then move forward and Google: "Is C++ backwards compatible with C"; and I clearly find out that it is not. And people say "C and C++ are two different languages".
If I assume the 2 following statements are true:
- C++ and C are two different languages.
- Every individual source file is written in a single language.
Does this mean that things like the above, which show up as "C features" are actually C++ features that for some historical reason just look exactly the same as C? Would this be a correct way of looking at these (just refer to them as ugly C++, instead of C)?
Furthermore, is there always a "more C++ way" of doing the same as the "C features" that are part of C++? If there is, how can I tell my compiler to warn me about the "C features" so I can the Google the "more C++ way" and change them in my source file?
I use g++ version 11.1.0
Which doesn't complain about e.g. printf
and int var[]
which leads me to believe that they are indeed "ugly C++", but still C++.
Thanks
EDIT
I disagree with this question being a duplicate. I am not asking about the differences between C and C++ (as the "related" questions posted in the comments).
I am asking: Is the "C looking code" in a C++ file (which compiles with a C++ compiler) C or C++? Is the compiler helping me by mixing the C code with the C++? Or is it just really C++ only (which happens to look exactly like C).