i was wondering what are the two primary reasons programs are written in C/Cpp?
i was wondering what are the two primary reasons programs are written in C/Cpp?
1. because it's cool
2. because everyone is doing it
let me google that for you
trust me i googled it but i thought there was a more important answer
Google No. 2 says all. There is no more important reason. They are enough. Ever tried assembly?
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
1. UNIX is written in C. Nobody cares what Windows is written in.
2. More seriously, C++ (or OOP) can be used to solve larger more complex problems. Anyone who says differently has never had something complex to solve or if they did, they worked way too hard at it and never knew it.
3. Both pay pretty well. Fad languages come and go but coding in both of these will keep you employed.
Why exactly just 2 reasons?
In reality, there are many more than just 2 reasons to use C and/or C++ (mostly C++ though). For one thing, don't let anyone tell you it's no longer relevant (heck, even C is still relevant sometimes). Any language can be irrelevant to you, depending on what you want to accomplish. The C++ standard was recently updated, and despite the popularity of Java and C#, it's still a very commonly-used language. For example:
If you want to do any bigtime 3D game programming, especially for things like graphics engines or physics engines, you're going to use C++ because it is a good balance of speed and OOP. That may change in the future as computers and consoles become faster. But I doubt it, because as performance increases, so does demand for more realistic graphics, AI, physics, etc.
Other than Fortran, which my alma mater Purdue University STILL used for some Computational Fluid Dynamics stuff, C and C++ are also probably the best choice for scientific computing for those same reasons (very large data sets and good visualization require great performance). If you're familiar with MATLAB, even though it uses its own scripting language, the core engine is C++. I would guess Maple is too.
Embedded stuff (someone mentioned robots) like avionics also use C/C++ quite often. I am pretty sure stock market companies (at least from the job listings I've seen over the years) use it in their own software because there's a crapload of information flying around during the trading day that needs to be quickly analyzed.
And finally...
In my personal opinion, if you learn C++ and you get good at it, you'll already understand most of C. You'll be able to dive right into Java and C#, because you'll already be familiar with OOP, and with the majority of Java and C# syntax. Doing so the other way around, if you aim to learn multiple languages, is not the way to go. But that's just my experience. For me, it was the perfect starter's language.
Programs are written in C because programs are written in C. It's famous. It's universal. It's fast. And it's small. [And by small I mean the language has relatively few features to learn]
And a big part of it is that
UNIX is written in C.
Consider this post signed
That was the primary reason for developing the language, altho UNIX is slightly outdated right now in favor of POSIX systems which are again implemented in C.
C executables are also significantly smaller than C++ equivalents memory usage wise, which is why it is better for fundamental things like OS kernels and so on.
You might also want to check this out:
Computer Language Benchmarks Game
There are various criteria there, but with regard to execution speed C/C++ is still the "fastest" language/s in the world. (I think C++ actually has a 1% lead on C in the rankings there, and there is a language called ATS which is comparable to them. But beyond that, the C/C++/ATS group is still 30% faster than the next competitors, Java and C#).
So if you want to optimize memory and speed you would use C. If memory is a less important issue that making life easier for the programmer, you would use C++.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge