What are the advantages and disadvantages of using inline
and const?

Answer Posted / vivek mahto

Well for the inline..

Advantages-
inline is a compiler directive so it will make compiler to copy the whole function where it is required , So there is no stack frame required in the stack section for storing the address of the function .

Disadvantages-
inline should only be used for the long functions as it will require more space as well as more calculation time.

For the const...

Advantages--
If you want any variable to keep constant through out the program then you can use const keyword. It is stored in the read only of the initalized data segment , even the pointer storing it's location cannot change the value of it, pointer can just change the address to point at some other location.

Disadvantages--
As the const is not flexible so mostly people use #define which is more flexible than const

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is algorithm in c++ programming?

580


How do you clear a set in c++?

589


What happens when the extern "c" char func (char*,waste) executes?

624


Explain mutable storage class specifier.

614


Explain method of creating object in C++ ?

577






Define Virtual function in C++.

615


What is the need of a destructor? Explain with the help of an example.

549


Write a program to show polymorphism in C++?

615


What is ostream in c++?

557


How do you compile the source code with your compiler?

599


Write about a nested class and mention its use?

611


What is c++ library?

587


What do you mean by storage classes?

776


What is encapsulation in C++? Give an example.

576


Is c++ free?

568