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 a singleton c++?

545


State the difference between pre and post increment/decrement operations.

601


Is c++ used anymore?

582


How can a struct in c++ differs from a struct in c?

606


Why do we use vector in c++?

598






Are vectors passed by reference c++?

513


What are the advantages of using a pointer? Define the operators that can be used with a pointer.

599


which of the following is not an secondary constant a) array b) real c) union

1253


Incase of a function declaration, what is extern means?

513


Explain polymorphism?

580


What is the difference between multiple and multilevel inheritance in c++?

597


Is atoi safe?

589


What is the difference between the compiler and the preprocessor?

611


What are the various arithmetic operators in c++?

570


What are the advantages of pointers?

593