Structure of C++

Structure of C++

C++ program structure is divided into various sections, namely, headers, class definition, member functions definitions and main function.


Note: C++ provides the flexibility of writing a program with or without a class and its member functions definitions.

A simple C++ program (without a class) includes comments, headers, namespace, main() and input/output statements.

C++ is also called as Superset of C (it means any valid C program can also be a valid C++ program. ) !

Source code can be written to be platfrom independent and written to take advantage of platform. C++ typically compiled into machine code.


Difference Bitween C++ and Java

C++

C++ is an object-oriented language. However, in C language, single root hierarchy is not possible.

C++ is mainly used for system programming.

C++ was designed for systems and applications programming.

C++ supports the goto statement.

C++ supports multiple inheritance.

C++ supports operator overloading.

C++ supports pointers.

C++ is platform dependent.

C++ uses compiler only. C++ is compiled and run using the compiler which converts source code into machine code.

C++ supports both call by value and call by reference.

C++ doesn't have built-in support for threads.

Write once compile anywhere

Allows both procedural programming and object-oriented programming.

C++ supports Object-oriented features Procedural programming features.

In C++, you can't include the try/catch even if the function throws an exception.

C++ supports both method overloading & operator overloading.

It supports structures.

Java

Java is also an object-oriented language.It is a single root hierarchy as everything gets derived from java.lang.Object.

Java is mainly used for application programming. It is widely used in window, web-based, enterprise and mobile applications.

It was designed as an interpreter for printing systems but later extended as a support network computing.

Java doesn't support the goto statement.

Java doesn't support multiple inheritance through class. It can be achieved by interfaces in java.

Java doesn't support operator overloading.

Java supports pointer internally. However, you can't write the pointer program in java.

Java is platform-independent.

Java uses compiler and interpreter both.Source code is converted into bytecode.

Java supports call by value only. There is no call by reference in java.

Java has built-in thread support.

Write once run anywhere everywhere

Support object-oriented programming model.

Java support automatic garbage collection. It does not support destructors as C++ does.

In Java, try/catch must be defined if the function declares that it may throw an exception.

only supports method overloading. It does not provide support for operator overloading.

It does not support any structures.