Why should I use namespaces and int main in Code blocks while there are no namespaces in turbo c++ and I can use void main without returning any value as I learnt in schools. Is the compiler different, Is the C++ version different?
yes, Code Blocks is the better environment to work instead of Turbo C and C++.
CodeBlocks is an open-source, cross-platform (Windows, Linux, MacOS), and free C/C++ IDE . It supports many compilers, such as GNU GCC (MinGW and Cygwin) and MS Visual C++.
Overall: It's great for learning how to code and practicing both coding and debugging. Pros: Code::Blocks is free and very easy to use. It can be used to write, compile. and debug software in the C/C++ programming languages and is very beginner-friendly.
First of all, Turbo C++ is a compiler bundled with an IDE targetting MS-Windows. Code Block is an IDE supporting several compilers and platforms. That is the main difference between these two tools, so you are not comparing exactly the same things.
Secondly, int
is the standard return value for main
, which is also standard by convention in C and C++ for program source code entry points (1). C++ compilers operating in standard mode expect programs to be written that way, so your programs should conform these expectations, if you want to use conforming C++ compilers, which are what Code Block is supporting by default. However, I'm pretty sure that you code configure Code Block to use a specific compiler in a non compliant mode (or simply a non compliant compiler), since it is a flexible IDE; you might well be able to set it up to use Turbo C++, and thus make it compile non ANSI C++. That said, I don't think that Turbo C++ does not support ANSI C++.
Thirdly, Namespaces are a feature of C++, that you have to use if you want to use the standard C++ library, but nothing forces you to otherwise.
(1) the name is a convention, but the function itself is obviously necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With