Differences between C and C++
73
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
- New Interface of Google Search: Try Google Search's New Interface Now!!
Google Search is always favourite to all from the starting of Google search. - 2 weeks ago
- Fresh and unique contents for Search Engine Optimization: The secret talks of SEO and generating site contents
Millions of websites with billions of webpages are available in the cyberspace. - 5 weeks ago
- Free malware protection with Portable Anti Trojan Elite: The best malware blocker and malware remover for your compter
Recently malware is spreading very rapidly. - 5 weeks ago
- rundll32.exe - Application Error â The memory could not be "read". Click on OK to terminate the program.
Windows operating system is corrupted due to several virus infections. - 6 weeks ago
- PPV or PPC?: "Pay Per View or Pay Per Click?" - Which One is Better?
Pay per view (PPV) and pay per click (PPC) are two types of marketing advertising solutions which is used by the advertisers to reach targeted group of visitors. - 6 weeks ago
- Make Good Money with Good Articles and Get Quick Cash
Before going to the main content, I want to ask you tow question? - 6 weeks ago
- Hot Secrets Behind Good Articles: How and Why Good Writers Always Write Good Articles?
Before writing to Hubpages, I have no idea about good articles. - 6 weeks ago
- Backlinks And Backlinking: Search Engine Optimization and the Importance of Backlinks And Backlinking
If you do a small research on search engine optimization or high search engine ranking, then you must come across the term backlinks or backlinking. - 2 months ago
PrintShare it! — Rate it: up down flag this hub









