PDA

Click to See Complete Forum and Search --> : What is the different betweet C and C++


waheedrafiq
Oct 21st, 2001, 03:41 PM
What can i program in C that i can't program in C++ what is the main differents between the two.:mad:

jim mcnamara
Oct 21st, 2001, 04:24 PM
C++ provides more base functionality -- templates, classes, polymorphism, etc. -- than does base standard C.

In others words, a short answer: It's easier to do complicated stuff and do it with way fewer lines of code in C++.

Windows programming is fairly messy (or complicated), C++ makes it easier to program. In theory. It's up to the programmer to learn how and implement it.

Because there is more 'base' to C++, it takes longer to learn the basics than it does for C.

Vlatko
Oct 21st, 2001, 04:28 PM
The main difference is that C++ is object oriented and C is not. There are differences in casting, allocating memory and many other things. I will see if i can dig up some links.

filburt1
Oct 21st, 2001, 04:29 PM
C++ is object oriented, C is not.

jim mcnamara
Oct 21st, 2001, 04:45 PM
Guys - the poster knows not what objects are. He's tryin to figure out which langauge to start learning programming with.

And FWIW - you can write C++ in C - C is, in fact, object-oriented.
So, therefore, the main difference between the two is NOT that one is object oriented. C++ is a super-class of base C written in C. Not that the poster really understands what a class is, either.

If you don't believe me read the FAQ John posted at the top of this forum. By all means.

jim mcnamara
Oct 21st, 2001, 04:47 PM
Oh.

Arien, like your picture, nice idea - anyway, I assume it's you.

filburt1
Oct 21st, 2001, 04:55 PM
If you're talking about the sig, then thanks. :cool:

filburt1
Oct 21st, 2001, 04:58 PM
Gone a'Googlin':--- Phers <phers@yahoo.com> wrote:
> So what's the difference between C and C++?
>
> -phers

uhhh, thats not such an easy question to answer. dad would
know better than I but C and C++ are really very different.

the difference is a paradigm difference in the way you
program.

so in C you start programing and when run it just goes down
line by line and executes the commands sequencially. at some
point, tho, your program either gets too big or you start
doing the same thing again and again and its a waste of time
writing it twice and its hard to maintain cuz you have to
remember to apply all fixes to both copies of it.

so what ppl do is create "functions". these are chunks of
code that you pull out of the main list and seperate into
its own fragment. you put a name on it and there is special
syntax for defining "parameters" to pass in and out of the
function. then, inside the main code where it used to be
you just call that function name and the execution jumps to
it and then comes back to where you called it when it is
done. this allows you to concentrate on one specific task
in a function and then call it as many times as you want
from the main section. you can then share these functions
with ppl.

example: you might have a main C program that does this...
. ask user for a number, call it "A"
. ask user for another number, call it "B"
. ask user for another number, call it "C"
. add all numbers together and print the total
. add all numbers together and divide by 3, print this average
. exit

well, it might look like this...
main()
{
int A, B, C, D;
float E;

A = get_value_from_user();
B = get_value_from_user();
C = get_value_from_user();

D = A+B+C;
print "this is the sum: ", D;

E = (A+B+C)/3;
print "this is the average: ", E;
}

but lets say that you do that print the sum and
average of 3 numbers alot of times in your program.
instead of writing those last 4 lines over and over
again just pull them out and put them into 2 functions
and then expect that someone will give you 3 numbers
and you will return them the answer like this...
main()
{
int A, B, C, D;
float E;

A = get_value_from_user();
B = get_value_from_user();
C = get_value_from_user();

D = add_em(A, B, C);
print "this is the sum: ", D;

E = average_em(A, B, C);
print "this is the average: ", E;
}

function add_em(int foo1, foo2, foo3)
{
float foo4;

foo4 = foo1 + foo2 + foo3;
return foo4;
}

function average_em(int fooA, fooB, fooC)
{
float fooD;

fooD = (fooA + fooB + fooC)/3;
return fooD;
}

now... obviously that didnt save alot up in the main
code but if you're going to break something out into
its own function its going to be something that does
alot of work and has lots of code so it will be much
more adventagous. (sp?)

so, to get to your question... if you wanna do something
like keep track of someone's personal data like address
book, phone number, favorite color, and birthdate then
you create functions like add_birthdate, edit_birthdate,
add_address, edit_address, etc.. you then create a thing
called a struct which is a collection of data all in
one big ball that you give a name. so like you might have
these variables...

string name, addr_street, fav_color, addr_city, addr_state
int addr_zipcode, phone_num, addr_street_num
date birthdate

but in the above case Ive got like 9 variables to keep
track of for one person. that's alot. so if I call my
functions Im passing alot of variables. so a struct is
a C thing that gathers them all together and gives it
one name. like this...

struct a_person
{

string name, addr_street, fav_color, addr_city, addr_state
int addr_zipcode, phone_num, addr_street_num
date birthdate

}

ok, basically its cleaner to now have a struct with all your
data in it. problem is that you still have like 6 different
functions just sittin around and you have to call it with
passing so many variables like this...
add_addr(addr_street, addr_city, addr_state, addr_zipcode,
addr_street_num);

what C++ does is that it is "object-oriented" so instead of
thinking in variables and functions you now "think in" objects.
an object in C++ is grouping the data with the functions that
do stuff to that data together in one ball that is called an
object. its a way to organize stuff. so now you have that
struct but the functions are defined in that struct too (well
kinda... I think you can think about it that way).

now, instead of adding someone's address like this...

A = get_address_from_user();
add_addr(addr_street, addr_city, addr_state, addr_zipcode,
addr_street_num);

you can just call it like this...
a_person.add_address = get_address_from_user();

cuz the a_person object knows what to do when you give it
an address. it called add_addr function that is defined
inside and it knows what data ball ("struct" in C) to add
it to.

anyway, thats kinda it in a nutshell (I think). ask dad if
this is the right way to think about it.

basically C is raw and C++ is a wrapper ontop of C that has
extra keywords and syntax to setup these organizations of
data and functions together in what they call an object.
then new syntax for creating, populating, manipulating, and
deleting those objects. C++ is a superset of C - I think you
can do anything in C++ that you can do in C plus all the new
C++ stuff but not the other way around.

-dj

waheedrafiq
Oct 22nd, 2001, 07:18 AM
wow guy's that's cool so this means that i should start of learning C and then progress on with C++ because C is Raw its easy to understand the logic's behide it . and of course when you want to do program in days rather then months then C++ is your answer due to supernet am i right .

Zaei
Oct 22nd, 2001, 07:54 AM
The usual recommendation is to start with C++. You can still write C code in C++, but it makes it easier to progress to classes, templates, etc, once you get there, because some of it will already be in your head (templated functions, etc).

As jim said, You CAN write object oriented code in C, using structs and function pointers.

Z.

sail3005
Oct 22nd, 2001, 03:18 PM
Originally posted by waheedrafiq
wow guy's that's cool so this means that i should start of learning C and then progress on with C++ because C is Raw its easy to understand the logic's behide it . and of course when you want to do program in days rather then months then C++ is your answer due to supernet am i right .

Actually, there is no reason to learn C first. in fact, i have heard that it is harder for a C programmer to learn C++ than someone that does not know C.