Click here to Skip to main content
16,016,570 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
usually every c code can run with c-compiler but i need answer for
"the program code that run in c language not in c++ language?"
Posted
Updated 24-Jul-11 4:00am
v2
Comments
Richard MacCutchan 24-Jul-11 10:03am    
Please reword your question as it makes very little sense. Do you have a problem with your compiler or the code you are writing?

Because C and C++ are two different languages despite the fact that C++ evolved from C.
 
Share this answer
 
Comments
Stefan_Lang 25-Jul-11 7:20am    
Yes and no. C++ was developed specifically with compatibility to C in mind. In fact this is and was the most restraining factor, and the reason for many decisions that today are hard to understand. Many ideas that Java and other languages later picked up were considered for C++ and abandoned because it would have broken thousands of old C programs. Also note that early C++ compilers consisted of a precompiler that translated C++ code to C code and a C-Compiler backend.

There are very few cases where C style syntax will not be accepted by C++ compilers, and in those cases this is true only because the alternative would have been to restrict the scope of C++ to the point of uselessness. E. g. the concept of function overloading is crucial for OOP, but it required that all function declarations contain the full declarations for all parameter types, which is not neccessary in C.
First thing first
CPP is OO and C is structure oriented
in general compiler judge the code type with file extension. File with .c extension will not compiled as cpp.

Almost all c style code is excepted in cpp.

except
1) type casting.
example:
char *arr;
arr=LocalAlloc(LTPR,1024);//will be a error in C++ but will be ok in C


2) Function Declaration
In C you can use a function without declaration, it will create a warning but no compilation error, but if the definition does not exists it will create a linking error. in c++ you cannot use a function without declaration

3) about definition of variables
In C you cannot define a variables after statement begun, but in C++ you can define variables anywhere you want.

4) in global scope(not just under class) in CPP you can define multiple function with same name with different variable with types but in C you cannot define one function name twice.

thats all i can recall now.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900