What are the advantages and disadvantages of using inline
and const?
Answers were Sorted based on User's Feedback
Answer / nidhi singh
advantages of inline-no function calls need to be
generated.no stack required.
disadvantage -inline functions require more space..
the whole definition is copied.
by using const we insure the value of variable is not goin
to change..
Is This Answer Correct ? | 42 Yes | 13 No |
Answer / 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 |
What is a class template in c++?
Which bit wise operator is suitable for putting on a particular bit in a number?
Why is c++ difficult?
Who was the creator of c++?
Do you know what are pure virtual functions?
What is the fastest c++ compiler?
Explain this pointer?
What is the basic difference between C and C++?
What is the main purpose of c++?
What is the difference between delegation and implemented-in-terms-of?
You want to link a c++ program to c functions. How would you do it?
What are the benefits of oop in c++?