Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

C++ vs C#


Published on

Comparison of C++ and C#.

Published in: Technology
  • Login to see the comments

  • Be the first to like this

C++ vs C#

  1. 1. Comparison of C++ and C# Prepared by Sudip Vora
  2. 2. Topics • Difference between C# and C++. • Which is better in performance? • Explain with an algorithm, program and prove it.
  3. 3. Contents • Introduction • Difference between C++ and C# • Example of C++ • Example of C# • Algorithm and Program of C++ • Algorithm and Program of C# • Conclusion
  4. 4. Introduction • C++ is an object – Oriented programming language. It was developed by Bjarne Stroustrup at AT & T Bell Laboratories in Murray Hill, New Jersey, USA, I the early of 1980s. Stroustrup, an admirer of simula67 and strong supporter of C, wanted to combine the best of both the languages and create a more powerful language that could support object-oriented programming features and still retain the power and elegance of C. The result was C++. • Therefore, C++ is an extension of C with a major addition of the class construct feature of simula67. Since the class was a major addition to the original C language Stroustrup initially called the new language ‘C with classes’. However, later in 1983, the name was changed to C++. The idea of C++ comes from the C Increment operator ++, thereby suggesting that C++ is an augmented – incremented version of C.
  5. 5. Introduction(Contd.) • C# (pronounced see sharp) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. It was developed by Microsoft within its .NET initiative. • The name "C sharp" was inspired by musical notation where a sharp indicates that the written note should be made a semitone higher in pitch.
  6. 6. Principles of C++ development • It should be "simple, object-oriented and familiar" • It should be "robust and secure" • It should be "architecture-neutral and portable" • It should execute with "high performance" • It should be "interpreted and dynamic "
  7. 7. Principles of C# development • It should be simple, modern, general-purpose, object-oriented programming language. • The language, and implementations should provide support for software engineering principles • The language is intended for use in developing software components suitable for deployment in distributed environments. • C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging from the very large that use sophisticated operating systems, down to the very small having dedicated functions. • Robustness, durability and programmer productivity are important.
  8. 8. Difference between C++ & C# C++ C# C++ compiles down to machine code. C# 'compiles' down to CLR, which ASP.NET interprets (roughly) Edit - As pointed out in comments, it JIT compiles, not interprets. In C++, you must handle memory manually. Because C# runs in a virtual machine, memory management is handled automatically. C++ support the multiple inheritance (of implementation). C# does not (although it does have multiple inheritance of interface). C++ includes a very powerful—and more complex and difficult to master— template meta language. C# originally had nothing like it, with many people believing that the common type hierarchy obviated the need for such techniques. In C++ you have to do your own memory management. C# has a garbage collector.
  9. 9. Difference between C++ & C#(Contd.) C++ C# Pointers can be used anywhere in C++. In C# pointers are used only in unsafe mode. Default access Specifier is Public in C++. Default access Specifier is Private in C++ is OOPS based. C# is Component & OOPS Based. C++ is a language that runs on all sorts of platforms, being extremely popular on Unix and Unix-like systems. C#, while standardized, is rarely seen outside Windows. C++ can create stand alone applications C# cannot. C++ can create only console applications. C# can create console applications, Windows applications, and ASP.NET Websites,Mobile Applications,etc.
  10. 10. Example of C++ #include<iostream.h> #include<conio.h> void main() { clrscr(); cout<<"n HELLO WORLD"; getch(); }
  11. 11. Example of C# using System; class Program { static void Main() { Console.WriteLine("Hello world!"); } }
  12. 12. Algorithm to calculate Area of a Rectangle Steps Description 1 Start 2 Ask the user for length and width of side 3 Store the value in box Length and Width 4 Calculate the area of the square (Length x Width) 5 Store the area in box Area 6 Print the value in box Area, appropriately labeled 7 Stop
  13. 13. Program of the above algorithm in C++ // Demonstration of variables #include <iostream.h> int main() { unsigned short int Width = 5, Length; Length = 10; // create an unsigned short and initialize with result // of multiplying Width by Length unsigned short int Area = Width * Length; cout << "Width:" << Width << "n"; cout << "Length: " << Length << endl; cout << "Area: " << Area << endl; return 0; }
  14. 14. Algorithm to calculate Area of a Rectangle Steps Description 1 Start 2 Ask the user for length and width of side 3 Store the value in box Length and Width 4 Calculate the area of the square (Length x Width) 5 Store the area in box Area 6 Print the value in box Area, appropriately labeled 7 Stop
  15. 15. Program of the above algorithm in C# using System; class Program { static void Main(string[] args) { double Length; double Area; Console.WriteLine("Enter the length of a side of Square :"); Length = Convert.ToDouble(Console.ReadLine()); Area = Length * Length; Console.WriteLine("The area of Square is: " + Area); Console.ReadLine(); } }
  16. 16. Conclusion • After going through various aspects of both, C++ and C#, we came to a point that we claim that C# is better than C++. C# has the features which C++ hadn’t. • C# has many features that overcome the features of C++ which are not at all present in C++. Hence, we conclude with C# is better than C++ in performance, usability and durability.