# Is it possible to have a function call on the left hand side of the equality operator?

173 views
Is it possible to have a function call on the left hand side of the equality operator?

a. No, because you can only have variables on the left side
b. Yes, but only in case of functions that do not return anything
c. Yes, but only in case of functions that return a pointer value
d. Yes, but only in case of functions that return a reference value.

#include<stdio.h>

int gA = 5;
int* fun()
{
return &gA;
}

int main()
{
*(fun()) = 5;
printf("%d", gA);
}

So, answer is C? No, because we used a '*' operator and only after it (getting lvalue) we could use "=" operator. But in C++ language we can use

#include<stdio.h>

int gA = 5;
int& fun()
{
return gA;
}

int main()
{
fun() = 5;
printf("%d", gA);
}

selected

## Related questions

1
498 views
Will the answer be $4$ or $2^5$?