Jump to content
xisto Community
Sign in to follow this  
hamza1405241548

C Or C++

Recommended Posts

well c and c++ are pretty much the same i think maybeand something that simple probably just works in both.do something more advanced and try it in the c and c++ compiler to see if that works in both.

Share this post


Link to post
Share on other sites

C was created prior to C++, as you might have expected, and thus has lesser capabilities. More precisely, C++ is an object-oriented programming language, while C isn't. Therefore, it would be logical for C++ to be able to do everything C can, but add more functionality at the same time.Now, I am not acquainted with either of these, but I can say with a great amount of certainty that classes are what make C++ an object-oriented language. A majority of languages used today are object-oriented, so C++ has an obvious advantage to C.

Share this post


Link to post
Share on other sites

Please check the extension of the program file wether you have put it as ".C" or ".CPP".

If you have put it as ".CPP" then it is quite natural as almost all the compilers can compile C as well as CPP programs ...

 

But if thats not the case then the compiler you are using is not a good one. A compiler is said to be erroneous if it compiles the program written in any other language other than what it is made for.

 

Dont get the wrong idea that if a compiler can compile both C and CPP programs than it is not a good one ... but it should compile only one language at a time.

Edited by nikhil (see edit history)

Share this post


Link to post
Share on other sites

Actually C++ evolved from C, therefore C++ is a Superset of C. In other words, code written in C will compile in C++, but not necessarily the other way round.In the sample you have written the statement starting with "cout" is definitely C++ as cout is an Object. Only Object oriented languages support Objects. C++ is object oriented and C is not.The rest of the sample is in C. But as mentioned earlier, it will work in C++ also.But todays compilers for C and C++ are so closely related that it is sometimes difficult for beginners to see where C ends and C++ starts. Also for the purposes of programming, it really does not matter, you can Mix C and C++ code in a program and the compiler will compile it and it will run perfectly ( if the code is written correctly :P

Share this post


Link to post
Share on other sites

Exactly, as stated a c++ compiler can, will, and SHOULD be able to compile c code without problem. Since c++ contains all of c, plus all the things special to c++ it is logical to assume one compiler can compile both c and c++. Now, c++ code shouldn't be able to be compiled in a c compiler since its lacking the capabilities to do so.If you really care, you should get a super super basic c compiler and try it out to see the problems that come when you compile c++ code in a c compiler. I imagine some c compilers are actually given the c++ compiling capabilities now just in case.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.