Hello everyone,
Before I start, I want to make sure everyone knows
this is not a list of technical differences between
C and C++ and that I am not some C/C++ guru. But I
do thinks it serves its purpose as a quick and
simplified look at the biggest difference between
C and C++.
I'll be using these hello world programs for reference.
/* hello.c
it is traditional to start all source files with a comment that
includes the filename, the author and why the program exists
*/
#include <stdio.h>
void main()
{
printf("Hello World\n");
}
// hello.cpp
// c++ can use both c-style comments
// and it's own style comments
#include <iostream>
void main()
{
cout << "Hello World" << endl;
}
In my schools, this hasn't even been an argument. Object Oriented is the thing of the now, and of the future, and Procedural programing will be a thing of legacy soon. However, I found procedural programing very easy to learn, and object oriented programing just a tad bit more difficult (but I did learn procedural first). Another argument for learning C before C++ is that the g++ compiler is basically extentions on the gcc compiler (gcc compiles c programs, g++ compiles c++ programs).
In the C file, the line that outputs the words "Hello World" to the screen is:
printf("Hello World\n");
printf() is a procedure that prints
things to the screen in a formated way.
That "\n" that tells the computer to go to a
new line can be thought of as formating. With
procuedural programs, you include any information that the
procedure will need inside the parenteses. In this case,
printf needs to know what we want it to print ("Hello World"
followed by a new line).
In the C++ file, the line that outputs the words "Hello World" to the screen is:
cout << "Hello World" << endl;In this case, cout is an object that represents the screen. I think of objects like cout as doorways. You use the stream insertion operator (the "<<") to show what follows ("Hello World" and "endl") where to go (out the cout door to the screen). "endl" works very similarly to "\n" - it's an instruction to end the line and go to the next one.
this is all I have time to write now, and it does cover the major difference. I hope this is somewhat helpful!