C++

Topic: Functions

What is inline function? Explain with an example.

An inline function is a combination of macro & function. At the time of declaration or definition, function name is preceded by word inline. When inline functions are used, the overhead of function call is eliminated. Instead, the executable statements of the function are copied at the place of each function call. This is done by the compiler. Consider following example:#include <iostream> using namespace std; inline int sqr(int x) {            int y;            y = x * x;            return y; } int main() {                int a =3, b;                b = sqr(a);                cout <<b;                return 0; }Here, the statement b = sqr(a) is a function call to sqr(). But since we have declared it as inline, the compiler replaces the statement with the executable stmt of the function (b = a *a)Please note that, inline is a request to the compiler. If it is very complicated function, compiler may not be able to convert it to inline. Then it will remain as it is. E.g. Recursive function, function containing static variable, function containing return statement or loop or goto or switch statements are not made inline even if we declare them so.Also, small functions which are defined inside a class (ie their code is written inside the class) are taken as inline by the compiler even if we don’t explicitly declare them so. They are called auto inline functions.

Browse random answers:

a)Why the six operators can't be overloaded? b)Why main() is a userdefined function?
What is virtual constructors/destructors?
In C++, do you know any function that given a real number x, gives us integers numerator and denominator? have a real x, and I'd like to know how it's written as a fraction. That is, I have the value for x, and I want to know the denominator d and the numerator n such as x = n/d.If you know a C++ library that has a function that gives me such integers, thanks.And sorry if my English isn't good xD
write the program which display the following out put. * * * * * * * * * * *
What are function prototypes?  
What is function overloading?  
Define Inline Function.
What is inline function? Explain with an example.
Explain the advantages of inline functions.
What happens when recursion functions are declared inline?
Do inline functions improve performance. Explain.
What is the difference between inline functions and macros? 
What are the characteristics of friend functions?
Advantages and disadvantages of using macro and inline functions.  
Explain the problem with overriding functions.  
What is the difference between inline functions and macros? 
Explain the advantages of using friend classes.  
Do inline functions improve performance? Explain.  
Guideline that should be followed while using friend function.
What happens when recursion functions are declared inline?  
What are the syntax and semantics for a function template?  
Explain the mechanism of virtual functions and virtual function tables.
Which of the following function prototype is perfectly acceptable?
Which of the following statement will be correct if the function has three arguments passed to it?
Show me how virtual function works in C++
What if the function is not declared virtual?
Why main function is special in C++ ?
What are the syntax and semantics for a function template?  
 Find any errors in the following function definition: void myfunction(int x,int y){   cout<<x*y;   return(x*y); }
Find any errors in the following function definition: int myfunction(int x,y){     return(x*y); }
what is the use of virtual destructor?
how can we made digital calendar by using c++ class
Differentiate persistent & non-persistent objects?
What is stand alone class and where it will be used? Describe with the help of an example.
What is encapsulation?
What is polymorphism? Explain with an example?
Explain the need for "Virtual Destructor".
What do you mean by pure virtual functions?
What are advantages of pure virtual function?
What do you mean by binding of data and functions?
Base class has some virtual method and derived class has a method with the same name. If we initialize the base class pointer with derived object,. calling of that virtual method will result in which method being called ?
What are Virtual Functions? How to implement virtual functions in "C"
What is virtual class and friend class?
What is the difference between shallow copy and deep copy also default copy is shallow or deep?
How do you mark a method obsolete?
explain Calling a Function?
Explain about Function Arguments ?
Explain Default Values for Parameters?
Can you override private virtual methods?
What is an explicit constructor?
What is abstraction in c++?
Can we take "main function" as of type float,char etc?
I want a program on INLINE function and demonstrate the program with INLINE function and without INLINE function.Because i want to know clearly the difference between INLINE FUNCTION AND FUNCTION?
What do you mean by inline function?
Please tell me all about dos.h and all its functions? how are the functions od dos.h are used ?
What is the difference between macro and inline()?
What is the difference between Function and Member function?
What are the types of STL containers?
What is void main mean?
How to write a program such that it will delete itself after execution?
What is a conversion constructor?
What do u meant by ?SBI? of an object?
Name the implicit member functions of a class. 
In a function declaration, what does extern mean? 
What do you mean by inline function?
What is the difference between delete and delete [ ]?
Difference between realloc() and free()?
What is friend function?
What does extern mean in a function declaration?
What is difference between function and procedure and how a function can be converted to procedure?
What is public, protected, private?
Is it possible to know that how much memory used by a member function or constructor?
What does the keyword virtual mean in the method definition?
What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?
Write a C++ Program to Convert Binary into Decimal Number