I have been getting comments and emails with questions, corrections and all kinds of insults (no, not that last one) and I decided to answer them all with this post which will clarify what is C and what is C + + and their differences.
C was created in 1972 by Dennis M. Ritchie at Bell Labs as an evolution of earlier language B, in turn based on BCPL.
C + + , meanwhile, was created in the mid-1980s by Bjarne Stroustrup. The intent of its creation was to extend the successful C programming language mechanisms that allow the manipulation of objects.
So C is the original language, while C + + is an extension of C, so the + +.
To me when I learned to program told me I'd learn to program in C + +, but I really only taught C, so many professors do not really know what it is programmed in C + +. Here is a hello world in two programs:
In C
In C + +
For the type of programs that are showing on this blog the most important difference is the input and output. So let's see an example of input and output for each program:
In C
In C + +
What I noticed these two little programs to do is to ask for an entry in C + + is much much simpler than in C. However, the issue of the <<and>> can get to 'scare' to newcomers to programming.
Request an entry in C
scanf ("switch", & name of the variable);
Ask a datum in C + +
cin>> name of the variable;
Display a data in C
printf ("Data: switch" variable name);
Display a data in C + +
court <<"Data:" <<name of the variable;
The modifiers are:% d for int,% f for float,% s for string,% c for char.
Libraries in C + +
For simple convention in C libraries ending in '. H' (point hache). All C libraries used for C + +, however, also by convention, the termination is removed. 'H' and best add 'c' at first.
Bookstore Bookstore C C + +
cmath math.h
string.h cstring
time.h ctime
etcetera.
The 'namespace'
C as a language has a set of reserved words, such as: if, for, while, int, float, ... C + + is an extension, so you have to add new keywords. These reserved words are in a 'namespace' (namespace). Specifically court and cin are the namespace std (standard).
If finds that we will use the std namespace (using namespace std;), whenever we wanted to use court,would have to write std:: court.
I hope that from now can identify whether a program is in C or C + +. I also hope to be publishing my programs in both languages from now.
0 comments:
Post a Comment