This isn't really a theory question, but a practical one.
C++ supports what you're asking about:
[C++14: 5.16/4]:
If the second and third operands are glvalues of the same value category and have the same type, the result is of that type and value category [..]
For example:
#include <iostream>
int x = 3, y = 4;
void foo(const bool b)
{
(b ? x : y) = 6;
}
int main()
{
std::cout << x << ' ' << y << '\n'; // 3 4
foo(true);
std::cout << x << ' ' << y << '\n'; // 6 4
foo(false);
std::cout << x << ' ' << y << '\n'; // 6 6
}
(live demo)
(This is basically the same as *ptr = val
, since dereferencing produces an lvalue.)
It's worth noting that C doesn't support it:
#include <stdio.h>
#include <stdbool.h>
int x = 3, y = 4;
void foo(const bool b)
{
(b ? x : y) = 6;
}
int main()
{
printf("%d %d\n", x, y); // 3 4
foo(true);
printf("%d %d\n", x, y); // 6 4
foo(false);
printf("%d %d\n", x, y); // 6 6
}
// main.c: In function 'foo':
// main.c:8:17: error: lvalue required as left operand of assignment
// (b ? x : y) = 6;
^
(live demo)
… though it will allow you to simulate this technique, by applying my early observation regarding pointer dereferences:
*(b ? &x : &y) = 6;
*ptr = val