Benefits of C / C++ over Other Programming Languages
History of C:
C is a middle level programming language developed by Dennis Ritchie during the early 1970s while working at AT&T Bell Labs in USA. The objective of its development was in the context of the re-design of the UNIX operating system to enable it to be used on multiple computers.
UNIX had been designed in 1969 by Ken Thompson, who wrote the system in assembly language in a DEC PDP-7 computer. Thompson made improvements and added expansion to complete the system. Brian W. Kernighan named the system UNIX, mostly written in assembly code.
However, besides assembler and FORTRAN, UNIX also included an interpreter for the programming language B. This language B was now used for improving the UNIX system. Being a high level language, B allowed much faster production of code than in assembly language. Still, B suffered from drawbacks as it did not understand data-types and did not provide the use of “structures”.
These drawbacks became the driving force for Ritchie for development of a new programming language called C. He kept most of language B’s syntax and added data-types and many other required changes. Eventually C was developed during 1971-73, containing both high-level functionality and the detailed features required to program an operating system. Hence, many of the UNIX components including UNIX kernel itself were eventually rewritten in C.
Riding on these advantages, C became dominant and spread quickly beyond Bell Labs replacing many well-known languages of that time, such as ALGOL,PL/I etc. Customization of language followed next and organizations started designing their own version of the language. This led to lack of standardization and created a new problem for system developers which forced American National Standards Institute (ANSI) in 1983 to form a committee to establish a standard definition of C. In 1988, they established the standard definition ANSI C. Further in 1990, ANSI C was approved by the International Standards Organization (ISO) .
C99 standard was the next revision; it was published in 1999 and introduced new features like advanced data types etc.
Benefits of C
- As a middle level language, Ccombines the features of both high level and low level languages. It can be used for low-level programming, such as scripting for drivers and kernels and it also supports functions of high level programming languages, such as scripting for software applications etc.
- C is a structured programming languagewhich allows a complex program to be broken into simpler programs called functions. It also allows free movement of data across these functions.
- C language is case-sensitive.
- C is highly portableand is used for scripting system applications which form a major part of Windows, UNIX and Linux operating system.
- C is a general purpose programming language and can efficiently work on enterprise applications, games, graphics, and applications requiring calculations.
- C language has a rich library which provides a number of built-in functions. It also offers dynamic memory allocation.
History of C++
The origin of C++ dates back to 1979 when BjarneStroustrup, also an employee of Bell AT &T, started working on language C with classes. He borrowed desirable features from many other languages like Simula, Ada, ML, CLU and ALGOL 68. Thus, in addition to features of C language, C++ also included classes, strong type checking, default function argument and basic inheritance. Till 1983, it was called C with classes, and in 1983 it was named C++. During 1998, a joint ANSI-ISO committee released the specification for C++ language standards.
In mid-2011, C++11, a new C++ standard was released. It was considerably influenced from the Boost library project and many of the new modules were sourced directly from the corresponding Boost libraries. It also added other new features including a comprehensive randomization library, regular expression support , a new C++ time library, a standard threading library, atomics support, auto keyword, improved support for unions and array-initialization lists, new templates and container classes. C++14, released in December 2014, included smaller improvements and bug fixes over C++11.
Benefits of C++
- C++ is a highly portablelanguage and is often the language of choice for multi-device, multi-platform app development.
- C++ is an object-oriented programming languageand includes classes, inheritance, polymorphism, data abstraction and encapsulation.
- C++ has a rich function library.
- C++ allows exception handling, and function overloading which are not possible in C.
- C++ is a powerful, efficient and fast language. It finds a wide range of applications – from GUI applications to 3D graphics for games to real-time mathematical simulations
Normal difficulties faced by a student while solving C,C++ problems
When you’re just starting out with programming, it’s easy to run into problems that make you wonder how anyone has ever managed to write a computer program. But the fact is, just about everyone else who’s learned to code has had that experience and wondered the same thing, when they were starting out. I’ve helped teach several introductory programming classes, and there are some problems that trip up nearly every student–everything from getting started to dealing with program design.
Getting set up
Learning to program is hard enough, but it’s easy to get tripped up before you even begin. First you need to choose a programming language (I recommend C++), then You need a compiler and a programming tutorial that covers the language you chose and that works with the compiler that you set up. This is all very complicated, and all before you even start to get to the fun parts.
If you’re still struggling with getting the initial setup, then check out our page on setting up a compiler and development environment (Code::Blocks and MINGW) which walks you through setting up a compiler with a lot of screenshots, and gets you up to the point of having an actual running program.
Thinking Like a Programmer
Have you seen the State Farm commercials where the car wash company returns the cars to customers with the soap suds still on the car? The company washes the car, but it didn’t rinse it. This is a perfect metaphor for computer programs. Computers, like that car wash company, are very literal. They do exactly, and only, what you tell them to do; they do not understand implicit intentions. The level of detail required can be daunting at first because it requires thinking through every single step of the process, making sure that no steps are missing.
Compiler Error Messages
This may seem like a small thing, but because most beginners aren’t familiar with the strictness of the format of the program (the syntax), beginners tend to run into lots of complaints generated by the compiler. Compiler errors are notoriously cryptic and verbose, and by no means were written with newbies in mind.
That said, there are a few basic principles you can use to navigate the thicket of messages. First, often times a single error causes the compiler to get so confused that it generates dozens of messages–always start with the first error message. Second, the line number is a lie. Well, maybe not a lie, but you can’t trust it completely. The compiler complains when it first realizes there is a problem, not at the point where the problem actually occurred. However, the line number does indicate the last possible line where the error could have occurred–the real error may be earlier, but it will never be later.
Finally, have hope! You’ll eventually get really good at figuring out what the compiler actually means. There will be a few error messages that today seem completely cryptic, even once you know what the real problem was, that in a few months time you will know like an old (if confused) friend. I’ve actually written more about this in the past; if you want more detailed help, check out my article on deciphering compiler and linker errors.
Debugging is a critical skill, but most people aren’t born with a mastery of it. Debugging is hard for a few reasons; first, it’s frustrating. You just wrote a bunch of code, and it doesn’t work even though you’re pretty sure it should. Damn! Second, it can be tedious; debugging often requires a lot of effort to narrow in on the problem, and until you have some practice, it can be hard to efficiently narrow it down. One type of problem, segmentation faults, are a particularly good example of this–many programmers try to narrow in on the problem by adding in print statements to show how far the program gets before crashing, even though the debugger can tell them exactly where the problem occurred. Which actually leads to the last problem–debuggers are yet another confused, difficult to set up tool, just like the compiler. If all you want is your program to work, the last thing you want to do is go set up ANOTHER tool just to find out why.
To learn more about debugging techniques, check out this article on debugging strategies.
Designing a Program
When you’re just starting to program, design is a real challenge. Knowing how to think about programming is one piece, but the other piece is knowing how to put programs together in a way that makes it easy to modify them later. Ideas like “commenting your code”, “encapsulation and data hiding” and “inheritance” don’t really mean anything when you haven’t felt the pain of not having them. The problem is that program design is all about making things easier for your future self-sort of like eating your vegetables. Bad designs make your program inflexible to future changes, or impossible to understand after you’ve written. Frequently, bad design exposes too many details of how something is implemented, so that every part of the program has to know all the details of each other section of the program.
One great example is writing a checkers game. You need some way to represent the board–so you pick one. A fixed-sized global array: intcheckers_board. Your accesses to the board all go directly through the array: checkers_board[x][y] = ….; Is there anything wrong with this approach? You betcha. Notice that I wrote your accesses to the board all go directly through the array. The board is the conceptual entity–the thing you care about. The array happens to be, at this particular moment, how you implement the board. Again, two things: the thing you represent, and the way you represent it. By making all accesses to the board use the array directly, you entangle the two concepts. What happens when you decide to change the way you represent the board? You have an awful lot of code to change. But what’s the solution?
If you create a function that performs the types of basic operations you perform on the checkers board (perhaps a get_piece_on_square() method and a set_piece_to_square() method), every access to the board can go through this interface. If you change the implementation, the interface is the same. And that’s what people mean when they talk about “encapsulation” and “data hiding”. Many aspects of program design, such as inheritance, are there to allow you to hide the details of an implementation (the array) of a particular interface or concept.
Leave Your Comment