Obtaining an address given a (run time) variable name
DLearner
bmqazwsx123 at gmail.com
Mon Jan 20 19:03:09 UTC 2025
// In the code below, what fn needs to go in the commented-out
line,
// to make the program print 7, 11 rather than 7, 7?
```
void main() {
import std.stdio;
int IntVar1 = 5;
int IntVar2 = 7;
int IntVar3 = 11;
int* wkVarAddr;
char[] wkVarName;
wkVarAddr = &IntVar2;
writeln("*wkVarAddr = ", *wkVarAddr);
wkVarName = cast(char[])("IntVar3");
// wkVarAddr = fn (wkVarName);
writeln("*wkVarAddr = ", *wkVarAddr);
}
```
More information about the Digitalmars-d-learn
mailing list