Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What are advantages of C++ when comparing with C?

Answer Posted / guriqbal singh

1: Stronger Type Checking - the use of classes, inheritance
&amp; automatic type

conversions mostly eliminates the need for the abominable
void* of C.



2: Type safe linkage - you can't accidentally call a routine
from another

module with the

wrong type and/or number of arguments - even if your header
files get out of

date.



3: A complex data type is provided. It includes all the
standard arithmetic

operations, implemented as operators, not function calls.



4: User-defined operators and function overloading are
supported. When you

design a data type you can specify which operators &amp;
functions are provided.



5: You can use class libraries to provide robust new data
types which can be

made exceptionally easy to use.

For example, the Rogue Wave 'math.h++' class library
implements general

multi-dimensional arrays which can be manipulated with
high-level operations

and an intuitive syntax:



DComplexArray a(10,10); // Construct a 10x10 complex array

cin >> a; // read it in from standard input

DComplexArray b = inverse(a); // Calculate the inverse

cout << b; // write out the inverse

cout << variance(b.diagonal()); // write out the variance of
the diagonal

elements of b



6: You can define automatic type conversions to convert
between data types.

For example, the Rogue Wave library provides a conversion
from a double array

to a complex array.



DoubleVec a(10, 0.0, 1.0); // Construct a double vector in
initialised to

{0,1,2,3,4...

DComplexVec z = a; // Construct a complex vector initialised to

{(0,0),(1,0),(2,0),...

cout << a; // write them out

cout << z;

cout << cos(z)*exp(DComplex(0,1)*a);



7: Provides inline functions which combine the efficiency of
using macros

with the safety of using functions - simply prepend the word
'inline' in

front of the function - if the compiler can inline it, it will.



inline Double

SumOfPositiveElements

(const DoubleVec&amp; v)

{

Double theSum = 0;

for (int i = 0; i < v.length(); i++) {

if (v[i] > 0) {

theSum += v[i];

}

}

return theSum;

}



8: C++ Compiles most ANSI C code directly and can call
compiled C code

directly, so you don't even have to learn anything new at all!

I recently spent some time converting a copy of SUPER to
ANSI C on a

Macintosh and was able to compile it equally easily with C++
as well. The

C++ version also had the advantage that it worked when I
finished, I had

managed to break the C version so that it crashed almost
immediately.



9: You don't have to put all of your declarations at the top
of each block

in C++. This means

that you can organise your code into logically related
'paragraphs' complete

with their necessary declarations. This makes code much more
maintainable -

you can easily move sections of code around, taking the
necessary

declarations along at the same time. If you use the const
modifier you can

also ensure that variables whose value should not change
after it is first

calculated do not do so.



Double x,y; // Declare two variables

cin >> x >> y; // read in their values

const Double sqrtX = sqrt(x); // Calculate the square roots

const Double sqrtY = sqrt(y);

cout << sqrt(sqrtX+sqrtY);

sqrtX = 42; // Will give an error...



10: Classes provide extensible types, promoting code reuse.
This can

result in major savings in the amount of code written. I saw
a recent

article which stated that the new Taligent operating system,
which is written

in C++, consists of 250,000 lines of code, whereas
WindowsNT, written in C,

was said to consist of 4,000,000 lines of code

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is c the same as c++?

954


How to declare a pointer to an array of integers?

1073


How can an improvement in the quality of software be done by try/catch/throw?

1003


Is there a sort function in c++?

936


What is the difference between a type-specific template friend class and a general template friend class?

931


Explain the difference between using macro and inline functions?

1053


When should you use global variables?

1148


How does list r; differs from list r();?

1087


What is purpose of abstract class?

1018


Comment on assignment operator in c++.

1073


What are the uses of c++ in the real world?

980


Is it legal in c++ to overload operator++ so that it decrements a value in your class?

1007


Is java easier than c++?

956


What is a c++ map?

1298


write asingle linked list which read from two list & the do the following 1 sort the prime & nonprime num (prime should be less tn nonprime) 2 each node has a prime num followd by nonprime 3 add a new node into its sutable plce 4 erase the most three duplicated non prime num 5 find the least duplicated prime num

2581