B
blangela
I am teaching a C programming course to C++ programmers and want to
come up with list of _KEY_ differences between the two languages.
Below is a list I have come up with so far. Have I missed any?
Key Differences between ANSI C and C++
1. C is a procedural programming language (where as C++ is an Object
Oriented Programming language). This means that the C programming
language does not support classes and all functionality provided
directly or indirectly through classes. Therefore C does not support
inheritance, polymorphism or encapsulation of data. C does support
"struct"s, which are like classes without support for member functions
and with no ability to encapsulate the data members that are defined
as belonging to the struct (a struct is an ADT).
2. C does not have access to the iostream library. Input and output in
C is done using the stdio.h library which provides access to the
scanf() and printf() functions, used to do input and output
respectively.
3. C does not support exception handling.
4. C does not support templates.
5. C does not support namespaces.
6. C does not support references.
7. C does not support default parameter values.
8. C does not support overloaded function names.
9. C does not allow you to declare a variable in a for statement
header (but C99 does!).
10. C requires that all variables of block scope must be declared at
the beginning of the block (not the case with C99!).
11. C does not support the new and delete operators. Dynamic
variables are created using the malloc() and free() functions, as well
as the calloc() and realloc() functions.
12. C does not support the four C++ cast operators static_cast,
dynamic_cast, const_cast and reinterpret_cast. All casts must be done
using the "C-style" cast operator.
13. C does not support inline functions (but C99 does!).
14. C does not support the unary scope operator.
15. C does not support // to start a comment (but C99 does!).
16. C include file names for C libraries are usually different than C+
+ include file names for the same libraries, even though they contain
prototypes for the same C functions. Generally you remove the leading
'c' and append ".h" to the end of the file name. For example the C++
<cstdio> include file is <stdio.h> in C; the C++ <cstdlib> include
file is <stdlib.h> in C; and the C++ <ctime> include file is <time.h>
in C.
17. C does not support the types bool and long long (but C99 does!).
come up with list of _KEY_ differences between the two languages.
Below is a list I have come up with so far. Have I missed any?
Key Differences between ANSI C and C++
1. C is a procedural programming language (where as C++ is an Object
Oriented Programming language). This means that the C programming
language does not support classes and all functionality provided
directly or indirectly through classes. Therefore C does not support
inheritance, polymorphism or encapsulation of data. C does support
"struct"s, which are like classes without support for member functions
and with no ability to encapsulate the data members that are defined
as belonging to the struct (a struct is an ADT).
2. C does not have access to the iostream library. Input and output in
C is done using the stdio.h library which provides access to the
scanf() and printf() functions, used to do input and output
respectively.
3. C does not support exception handling.
4. C does not support templates.
5. C does not support namespaces.
6. C does not support references.
7. C does not support default parameter values.
8. C does not support overloaded function names.
9. C does not allow you to declare a variable in a for statement
header (but C99 does!).
10. C requires that all variables of block scope must be declared at
the beginning of the block (not the case with C99!).
11. C does not support the new and delete operators. Dynamic
variables are created using the malloc() and free() functions, as well
as the calloc() and realloc() functions.
12. C does not support the four C++ cast operators static_cast,
dynamic_cast, const_cast and reinterpret_cast. All casts must be done
using the "C-style" cast operator.
13. C does not support inline functions (but C99 does!).
14. C does not support the unary scope operator.
15. C does not support // to start a comment (but C99 does!).
16. C include file names for C libraries are usually different than C+
+ include file names for the same libraries, even though they contain
prototypes for the same C functions. Generally you remove the leading
'c' and append ".h" to the end of the file name. For example the C++
<cstdio> include file is <stdio.h> in C; the C++ <cstdlib> include
file is <stdlib.h> in C; and the C++ <ctime> include file is <time.h>
in C.
17. C does not support the types bool and long long (but C99 does!).