Differences between C and C++
By rancidTaste
C and C++ both are programming languages. Actually, C++ was based on C & retains a great no of functionality. Both of them have some similarities and differences. In this page, some of the differences between C and C++ are noted below:
OOP (Object Oriented Programming) concepts:
C++ supports object oriented programming concepts. But C doesn't support OOP (Object Oriented Programming). C is actually a POP (Procedure Oriented Programming) language.
Memory allocation
n C, to allocate memory space (both single elements and arrays) malloc(), calloc() function are used and you can also free the memory using free() fucction. For example:
int *a = malloc( sizeof(int) ); int *a_array = malloc( sizeof(int) * 20 );
free( a ); free( a_array );
But for C++ the situation is a bit different. For the allocation of memory use new[] operator and use delete[] to free the memory space. For example:
int *a = new int; int *a_array = new int[20]; delete a; delete[] a;
Predecessor:
C is the predecessor of C++. A lot of C remains in C++. C++ allows programmer to program more easily then using C.
No Boolean Type
C++ can provide a native boolean type. But C does not provide a native boolean type. To simulate it, you have to use an enum, though:
typedef enum {FALSE, TRUE} bool;Level of language
C++ is high level language. Whereas C is a low level language.
Syntax supporting:
C++ support all the syntaxs of C. But C doesn't support all the syntax of C++
Function supporting:
C++ can support of all function of C language, but C can't support of all function of C++ language.
Function declaration before to use
Most good C programs follow that the function should be declared before to use. You may also define other places also. But for C++, it's strictly enforced that all the functions must have to be declared before to use.
C++ contains a largeer library
C++ has a much larger library than C. Moreover, some things may be automatically linked in by C++ when they are not with C. For instance, if you're used to using g++ for math-heavy computations, then it may come as a shock that when you are using gcc to compile C, you need to explicitly include the math library for things like sin or even sqrt:
% g++ foo.cc
main Doesn't Provide return 0 Automatically
In C++, if you don't mention return 0 at the end of main, it is provided automatically. For example:
int main()
{
printf( "Hello, World" );
}
But in C, it must be added manually. Otherwise, the copiler shows an error during the compile time and running time. For example,
int main()
{
printf( "Hello, World" );
return 0;
}
Creating Classes:
C++ allows the programmer to create classes (Classes are similar to C structures). But C doesn't allow programmers to create classes.
Operator and function overloading
Operator and function overloading is not supported by C. If a function has a name, then that function can't use in the program again. But using C++, that is possible. You can use the same function name with different arguments.
Char string limit
C can only recognizes first 32 char of string. But C++ doesn't pose this type of limitation.
Top down or bottom up approach
C programming follows Top Down aproach and focuses on procedures. Whereas C++ is a bottom up approach and focuses on data (data hiding, abstaction).
Prototyping
Prototyping is an optional in for C programming. But it's a mandatory in C++ programming.
Void pointer assigning to a non-void pointer
Using C, assigning a void pointer to a non-void pointer is possible. But C++ does not bearing such type of concepts.
void *ptrx="vaibhav";
char *ptry="Vai"
;
ptry=ptrx // only valid in C
All these are the differences between C and C++. If you want to include many other differences, please add it to the comment section.
© Written by rancidTaste
If you are enjoyed this post, please consider to leave a comment at the comment section of this page or Subscribe to rancidTaste's RSS feed to get new pages which will be delivered to your feed reader. You can also read more hubs by rancidTaste.
Recent pages of itis123
- How to install Twitter widget into your blog?
Twitter, is becoming very popular day-by-day and a free social messaging utility for staying connected in real-time with your friends.
- How to add "Top of the page" icon to your blog?
"Top of the page" icon link is an important thing if your blog post is long.
- How to find out and change the size of your blog's header image?
Blogger header image gives the uniqueness of your blog among the millions of blogs.
- Troubleshooting
If you are a compute user, then you may face several types of problems at different times.
- ESET NOD32
Virus, Malware, Trojan, Worm, Spyware, Adware, Botnet etc.
- NOD32 keys
ESET NOD32 is one of the best effective and most proactive antivirus software and malware protection.
- How to Get Free ESET NOD32 Antivirus Key And Password
Different antivirus software are used to protect our PC form virus.
- Changing Your Blog's Header Image
You can easily add your favorite image or photo as a blog's header image.
rancidTaste's recent pages
- Drawing a line: How to draw a line using HTML 5?
HTML5 canvas API provides basics tools and great supports to draw and style different types of sub paths including lines, arcs, Quadratic curves, and Bezier curves, as well as a means for creating paths by connecting sub paths. - 5 days ago
- SEO Pages
SEO, Search Engine Optimization and Keywords - these common three terms are the brainstorming terms for any content publisher, seo company, seo service provider, seo researcher, seo firm, seo consultant, seo professional or other seo lover. - 3 months ago
- WordPress.org vs. WordPress.com: An explained comparison between WordPress.org an WordPress.com
WordPress is a common name but do you know that there are two things: WordPress. - 3 months ago
- Creating database from cpanel: How to create a database from cpanel hosting?
A step by step full tutorial to create a database from cpanel hosting account for any dynamic website. - 3 months ago
- Natural Join in Database: Retrieving records from more than one table with Natural Joins
Natural Join is one of the sql joining. - 3 months ago
- Explanation of SQL Join: Obtaining data from multiple tables using Join
Explanation of SQL Join: Obtaining data from multiple tables using Join. - 3 months ago
- How to solve "CreateFile error 32 when trying set file time" Error During Oracle Installation
Solution of the Oracle installation problem on Windows 7 / Windows XP during Oracle installation start-up. - 3 months ago
- A Brief Explanation of SQL Statements and Classification
Any type of database is based on several statements. - 3 months ago
bfg 2 years ago
realy gud one