difference between c and c++

Posted 10 February 2009 - 01:13 PM

hi
can n e one plz clear my concepts about difference in c and c++,,wat i know is dat c++ is an OOP language,,and i know dats true,,but i don't know y it is called OOP and C is not OOP,,
plz tell me by giving examples,,like c program in C and C++,,and difference between them

Re: difference between c and c++

Posted 10 February 2009 - 02:16 PM

C can be thought of as a subset of C++, but C++ offers a vast quantity of improvements, including the introduction of object oriented programming.

Object Oriented Programming is as described by Beta. C was not object oriented, but procedural, in that you had functions that would carry out tasks upon different variables, and basically everything was a member of the same scope, besides the ocassional use of a struct. C++ allowed variables and functions to be "encapsulated" into classes, of which instances called objects could be created. These objects could then interact with eachother, and their data was protected from any miswritten function. Also, with this addition, databasing was greatly enhanced, as it became much easier to control and contain vast amounts of information in memory.

Re: difference between c and c++

One of the biggest differences between C and C++ is inheritance. It is true in C you can actually have inheritance but it is much different then C++.

Lets say you wanted to make health crate and weapon crate classes in c++ and c.

Well to do it in C++ you would go about making a base class that both use to define a basic crate. Then you would derive a health crate class and a weapon crate class off of that base class. Like follows.

Now to do this in C you would have to have a structure defined for crate, then health and weapon crate would both have to store an object of crate inside of them instead of in C++ where they are actually a crate. So this is just one small difference between c and c++, there are a lot more so I recommend doing some extensive reading to find out more information between the two.

Re: difference between c and c++

Posted 13 February 2009 - 01:20 AM

well thanks all of you,, after reading all of yours posts i just understand that there is a difference of objects and classes in c and c++,,like we work in objects and classes in c++ while in c we do not,,indeed we can't,,,
but now i have some more questions,,,what are these classes and objects???
about objects i just know that objects are like pre-defined functions like,,int, float, default, etc etc or u can say those words which we can not use in our program,,for example if we write a word default then it will not work in that way in which we want but it will work for that specific task which had been already given to it by c or c ++

and i have no idea of classes,,

i am ashamed of my self that i didn't know the basics so i am sorry if i am asking you silly queations but i want to clear my concepts,
thanks

Re: difference between c and c++

Posted 13 February 2009 - 11:42 AM

One objective of programming is to emulate the real world as closely as possible. THis involves making program equivalents of what exists in the real world. The best way to do ths is to create objects in programs as we have in the real world. So we can make a ball....

class ball
{
int size;
void bounce();
}

or more complicated things, like a car that is a vehicle and has a motor

class car: public vehicle
{
Motor& engine;
void drive();
}

objects make all of this possible as nothing else could. We would be lost without them.

Re: difference between c and c++

Posted 13 February 2009 - 02:17 PM

Objects are metaphorcial e.g. Cat class is a child of Animal class and has properties related to same. However, in a more practical sense, they're organizational. They allow all the logic relating to a given thing to become part of that thing. The thing only has to share as much information as need for other things to work with it.

I know, confusing as hell. Let's just go with organizational. Here's the skeleton of a Tic Tac Toe program.

This code got a little longer, but it has a lot more going on. The object initialized itself automatically, so the user doesn't have to worry about that. It also has a number of validation checks, so bad data can't get into the board. All the values that were just there in the C version now have hard associations with the class. Usage of the object is actually simpler, which is usually to goal.

Re: difference between c and c++

Posted 15 February 2009 - 02:25 AM

::
:: C contains only C-Style Structure which can only contains
:: data and cannot be used for Data Structures ...
::
:: C++ there are structure, class, union, and other new things
:: like operators too and the whole OOP too !
::