Skip to content
Related Articles

Related Articles

Can we use function on left side of an expression in C and C++?
  • Difficulty Level : Easy
  • Last Updated : 29 May, 2017

In C, it might not be possible to have function names on left side of an expression, but it’s possible in C++.




#include<iostream>
  
using namespace std;
  
/* such a function will not be safe if x is non static variable of it */
int &fun()
{
   static int x; 
   return x;
}    
  
int main()
{
   fun() = 10;
  
   /* this line prints 10 on screen */
   printf(" %d ", fun());
  
   getchar();
   return 0;
}

Please write comments if you find anything incorrect or want to share more information about the topic discussed above.

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :