search
Log In
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
2 votes
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.
in Object Oriented Programming 173 views

1 Answer

4 votes
 
Best answer
#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);
}

So, answer is D


selected by

Related questions

3 votes
2 answers
2
1 vote
1 answer
3
96 views
which function will going to be call first? x = f1() + f2() is it compiler dependent ?
asked Jan 21, 2018 in Programming hacker16 96 views
2 votes
1 answer
4
...