Difference between C and C++ - GeeksforGeeks (2025)

Last Updated : 07 May, 2024

Comments

Improve

Similarities between C and C++ are:

  • Both the languages have a similar syntax.
  • Code structure of both the languages are same.
  • The compilation of both the languages is similar.
  • They share the same basic syntax. Nearly all of C’s operators and keywords are also present in C++ and do the same thing.
  • C++ has a slightly extended grammar than C, but the basic grammar is the same.
  • Basic memory model of both is very close to the hardware.
  • Same notions of stack, heap, file-scope and static variables are present in both the languages.

Difference between C and C++ - GeeksforGeeks (1)

Differences between C and C++ are:
C++ is often viewed as a superset of C. C++ is also known as a “C with class” This was very nearly true when C++ was originally created, but the two languages have evolved over time with C picking up a number of features that either weren’t found in the contemporary version of C++ or still haven’t made it into any version of C++. That said, C++ is still mostly a superset of C adding Object-Oriented Programming, Exception Handling, Templating, and a more extensive standard library.

Below is a table of some of the more obvious and general differences between C and C++. There are many more subtle differences between the languages and between versions of the languages.

CC++
C was developed by Dennis Ritchie between the year 1969 and 1973 at AT&T Bell Labs.C++ was developed by Bjarne Stroustrup in 1979.
C does no support polymorphism, encapsulation, and inheritance which means that C does not support object oriented programming.C++ supports polymorphism, encapsulation, and inheritance because it is an object oriented programming language.
C is (mostly) a subset of C++.C++ is (mostly) a superset of C.
Number of keywords in C:
* C90: 32
* C99: 37
* C11: 44
* C23: 59
Number of keywords in C++:
* C++98: 63
* C++11: 73
* C++17: 73
* C++20: 81
For the development of code, C supports procedural programming.C++ is known as hybrid language because C++ supports both procedural and object oriented programming paradigms.
Data and functions are separated in C because it is a procedural programming language.Data and functions are encapsulated together in form of an object in C++.
C does not support information hiding.Data is hidden by the Encapsulation to ensure that data structures and operators are used as intended.
Built-in data types is supported in C.Built-in & user-defined data types is supported in C++.
C is a function driven language because C is a procedural programming language.C++ is an object driven language because it is an object oriented programming.
Function and operator overloading is not supported in C.Function and operator overloading is supported by C++.
C is a function-driven language.C++ is an object-driven language
Functions in C are not defined inside structures.Functions can be used inside a structure in C++.
Namespace features are not present inside the C.Namespace is used by C++, which avoid name collisions.
Standard IO header is stdio.h.Standard IO header is iostream.h.
Reference variables are not supported by C.Reference variables are supported by C++.
Virtual and friend functions are not supported by C.Virtual and friend functions are supported by C++.
C does not support inheritance.C++ supports inheritance.
Instead of focusing on data, C focuses on method or process.C++ focuses on data instead of focusing on method or procedure.
C provides malloc() and calloc() functions for dynamic memory allocation, and free() for memory de-allocation.C++ provides new operator for memory allocation and delete operator for memory de-allocation.
Direct support for exception handling is not supported by C.Exception handling is supported by C++.
scanf() and printf() functions are used for input/output in C.cin and cout are used for input/output in C++.
C structures don’t have access modifiers.C ++ structures have access modifiers.
There is no strict type checking in C programming language.Strict type checking in done in C++. So many programs that run well in C compiler will result in many warnings and errors under C++ compiler.
C does not support overloadingC++ does support overloading
Type punning with unions is allows (C99 and later)Type punning with unions is undefined behavior (except in very specific circumstances)
Named initializers may appear out of orderNamed initializers must match the data layout of the struct
File extension is “.c”File extension is “.cpp” or “.c++” or “.cc” or “.cxx”
Meta-programming: macros + _Generic()Meta-programming: templates (macros are still supported but discouraged)
There are 32 keywords in the CThere are 97 keywords in the C++

Elevate your coding journey with a Premium subscription. Benefit from ad-free learning, unlimited article summaries, an AI bot, access to 35+ courses, and more-available only with GeeksforGeeks Premium! Explore now!


`; tags.map((tag)=>{ let tag_url = `videos/${getTermType(tag['term_id__term_type'])}/${tag['term_id__slug']}/`; tagContent+=``+ tag['term_id__term_name'] +``; }); tagContent+=`
`; return tagContent; } //function to create related videos cards function articlePagevideoCard(poster_src="", title="", description="", video_link, index, tags=[], duration=0){ let card = `

${secondsToHms(duration)}

${title}
${showLessRelatedVideoDes(htmlToText(description))} ... Read More

${getTagsString(tags)}

`; return card; } //function to set related videos content function getvideosContent(limit=3){ videos_content = ""; var total_videos = Math.min(videos.length, limit); for(let i=0;i

'; } else{ let view_all_url = `${GFG_SITE_URL}videos/`; videos_content+=`

View All

`; } // videos_content+= '

'; } } return videos_content; } //function to show main video content with related videos content async function showMainVideoContent(main_video, course_link){ //Load main video $(".video-main").html(`

`); require(["ima"], function() { var player = videojs('article-video', { controls: true, // autoplay: true, // muted: true, controlBar: { pictureInPictureToggle: false }, playbackRates: [0.5, 0.75, 1, 1.25, 1.5, 2], poster: main_video['meta']['largeThumbnail'], sources: [{src: main_video['source'], type: 'application/x-mpegURL'}], tracks: [{src: main_video['subtitle'], kind:'captions', srclang: 'en', label: 'English', default: true}] },function() { player.qualityLevels(); try { player.hlsQualitySelector(); } catch (error) { console.log("HLS not working - ") } document.getElementById('article-video-tab-content').style.display = 'block'; } ); const video = document.querySelector("video"); const events =[ { 'name':'play', 'callback':()=>{videoPlayCallback(main_video['slug'])} }, ]; events.forEach(event=>{ video.addEventListener(event.name,event.callback); }); // error handling for no compatible source player.on('error', function() { var error = player.error(); console.log("Video Error: ", error); if (error && error.code === 4) { console.log("No compatible source was found for this media."); hideVideoPlayer(); } }); }, function(err) { var player = videojs('article-video'); player.createModal('Something went wrong. Please refresh the page to load the video.'); hideVideoPlayer(); // hiding video in case of timeout (requirejs) console.log(err); }); // function to hide the video player function hideVideoPlayer() { var videoPlayer = document.getElementById('article-video'); if (videoPlayer) { videoPlayer.parentNode.removeChild(videoPlayer); } } /*let video_date = main_video['time']; video_date = video_date.split("/"); video_date = formatDate(video_date[2], video_date[1], video_date[0]); let share_section_content = `

${video_date}

`;*/ let hasLikeBtn = false; // console.log(share_section_content); var data = {}; if(false){ try { if((loginData && loginData.isLoggedIn == true)){ const resp = await fetch(`${API_SCRIPT_URL}logged-in-video-details/${main_video['slug']}/`,{ credentials: 'include' }) if(resp.status == 200 || resp.status == 201){ data = await resp.json(); share_section_content+= `

`; hasLikeBtn = true; } else { share_section_content+= `

`; } } else { share_section_content+= `

`; } //Load share section // $(".video-share-section").html(share_section_content); // let exitCond = 0; // const delay = (delayInms) => { // return new Promise(resolve => setTimeout(resolve, delayInms)); // } // while(!loginData){ // let delayres = await delay(1000); // exitCond+=1; // console.log(exitCond); // if(exitCond>5){ // break; // } // } // console.log(loginData); /*if(hasLikeBtn && loginData && loginData.isLoggedIn == true){ setLiked(data.liked) setSaved(data.watchlist) }*/ } catch (error) { console.log(error); } } //Load video content like title, description if(false){ $(".video-content-section").html(`

${main_video['title']}

${hideMainVideoDescription(main_video['description'], main_video['id'])}

${getTagsString(main_video['category'])} ${(course_link.length)? `

View Course

`:''} `); let related_vidoes = main_video['recommendations']; if(!!videos && videos.length>0){ //Load related videos $(".related-videos-content").html(getvideosContent()); } } //show video content // element = document.getElementById('article-video-tab-content'); // element.style.display = 'block'; $('.spinner-loading-overlay:eq(0)').remove(); $('.spinner-loading-overlay:eq(0)').remove(); } await showMainVideoContent(video_data, course_link); // fitRelatedVideosDescription(); } catch (error) { console.log(error); } } getVideoData(); /* $(window).resize(function(){ onWidthChangeEventsListener(); }); $('#video_nav_tab').click('on', function(){ fitRelatedVideosDescription(); });*/ });

Difference between C and C++ - GeeksforGeeks (2025)

FAQs

Difference between C and C++ - GeeksforGeeks? ›

C is a function driven language because C is a procedural programming language. C++ is an object driven language because it is an object oriented programming. Function and operator overloading is not supported in C. Function and operator overloading is supported by C++.

What is the difference between C and C++ answer? ›

The main difference between C and C++ is that C is a procedural programming language that does not support classes and objects. On the other hand, C++ is an extension of C programming with object-oriented programming (OOP) support. Is C and C++ a compiled or interpreted language? C and C++ are both compiled languages.

How difficult is C compared to C++? ›

C does not have so many rules and restrictins as C++ it is not so difficult to learn it because it is more direct to code. On other hand the C++ is more powefull to use. The conclusion is C is easier to learn, C++ is easier to use.

Why would you choose C rather than C++? ›

If you are interested in low-level programming tasks such as operating systems and device drivers, C may be your better choice. If you are more interested in developing higher-level applications such as web browsers and graphics software, C++ may be a better fit.

Is C worth learning over C++? ›

Learning C++ is valuable for those interested in pursuing a career in this field. Embedded Systems: C is commonly used in embedded systems programming, where resources are constrained. If you're interested in working on devices like microcontrollers or IoT devices, knowledge of C is beneficial.

Can I learn C++ without learning C? ›

Yes, you can learn C++ without C. While C++ is based on C, many of the concepts used in C++ development are different. C++ is object-oriented, so the development methodology may differ from most C applications.

Is it easy to learn C++ after C? ›

Switching from C to C++ can be both easy, as there are many similarities between the two languages, and hard, as there are many differences that require forgetting what you know and habits that you may have developed from programming in C.

Is C++ still relevant in 2024? ›

Yes, C++ is still a popular and in-demand programming language in 2024, and a career in C++ programming can be rewarding.

What is the hardest part of C language? ›

Understanding pointers is often regarded as one of the most challenging aspects of learning the C programming language. Many individuals struggle to grasp the concept of pointers due to the inherent complexity of comprehending how the central processing unit (CPU) and memory work together.

What is the hardest part of learning C++? ›

While C++ is a powerful language, it is also considered one of the most challenging to learn due to its complex syntax and steep learning curve. One of the main reasons C++ is so difficult to learn is its syntax. Unlike other programming languages, C++ has a lot of rules and exceptions that can be hard to remember.

What does C++ have that C does not? ›

C has no support for the OOPs concept. Thus, it does not support encapsulation, polymorphism, and inheritance. The C++ language supports encapsulation, inheritance, and polymorphism because it is an object-oriented programming language. C has no support for functions and operator overloading.

Which should I learn first C or C++? ›

C Because C is the most basic language among these 3. C++ is the upgraded version of C, so you can learn C++ more efficiently and understand much better if you learnt C before it.

Which is more powerful, C or C++? ›

C language seems to be more suitable for low-level programming applications, and it is also a foundational language for beginners, whereas C++ is an extension of C programming language with the OOP's concept, so it is more feasible for complex applications also it is faster, secure.

Why is C still being taught? ›

C is often used in operating systems, embedded systems, and other low-level applications. Learning C can be challenging, but it can provide a strong foundation in programming concepts such as data types, variables, functions, loops, and arrays.

Should I learn C or C++ for cyber security? ›

It is commonly accepted that most malware is written in the C/C++ programming languages and they are, therefore, an essential skill for cybersecurity professionals to possess.

Is C language worth learning in 2024? ›

C and C++

Surely python and JavaScript are easy-to-learn and easy-to-use languages for most of the applications but when it comes to choosing the fastest language then C and C++ are the best choices and it is one of the top programming languages in the programming world.

When should you use C vs C++? ›

OOP and templates are the nice things about C++, but anything written in C++ can also be written in C. If you don't need the additional abstractions that C++ provides, then C is the better language. Also, it is arguable that you can get better performance from plain-old-C in many cases.

How is C different from C++ variable? ›

C does not support information hiding. All variables are open to code access in C. C++ hides information by encapsulation and abstraction. Variables can be hidden in classes and modifiers used to make them inaccessible to outside users.

Is C++ just C with classes? ›

Although C++ was originally a derivation of C, and was originally referred to as "C with Classes", it has changed over the last few decades and is nothing like C. Sure, the syntax looks the same, but that can be said about Java too, and when's the last time you saw the phrase "C/Java"?

What is C++ used for? ›

C++ is used in fields such as system software, game development, embedded systems, scientific computing and high-performance applications. The C++ standard library provides a range of coding utilities and functions, making it easy to develop complex software systems.

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Tyson Zemlak

Last Updated:

Views: 5682

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.