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

Answers were Sorted based on User's Feedback



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

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

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

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

Post New Answer

More C++ General Interview Questions

What is struct c++?

0 Answers  


What is an accessor in c++?

0 Answers  


Comment on local and global scope of a variable.

0 Answers  


What is function overloading c++?

0 Answers  


What is else if syntax?

0 Answers  






Which operations are permitted on pointers?

0 Answers  


Can c++ do everything c can?

0 Answers  


Write a C++ program to sort digits of all the 4 digit number and display the sorted 4 digit number

1 Answers   TATA, TCS,


What is the best sorting algorithm, when there is a large amount of data, that cannot be fit in the main memory. ?

1 Answers   Yahoo,


i have given a project to create examination seating plan system in c++. so can anyone send me the answer of this question quickly??????

1 Answers  


Explain abstraction.

0 Answers  


wrong statement about c++ a)code removably b)encapsulation of data and code c)program easy maintenance d)program runs faster

11 Answers  


Categories