Getting variable variable in c

I have one requirement in C.

char abc[]="hello";
char hello[]="world";

Using abc, can we get the value of the hello variable in C. I know that this is possible in some languages, such as Perl, Php, Bash,.,

Is this possible in C?

+3
source share
6 answers

Yes, you are right, it is possible in some other language, but not in C, since abc is a container that is in a place (for example: 1000), and hello is another container that is in a different place (for example: 2000 ), so we don’t have contact between these two arrays,

we cannot make a value (string) to indicate another value. therefore, finally, THIS IS NOT ALL POSSIBLE.

+2
source

, C, , .

+2

C, , Perl Python. , . , . eval, , , .

+1

C , , , . , -, () ().

- . , -g (gcc) , . , , , .

+1

C. java .

0

POSIX , , hello :

void *handle = dlopen(NULL, RTLD_NOW);
// error handling omitted

printf("%s variable contains value %s", abc, (char *)dlsym(handle, abc));

dlsym() char * , printf - .

And you need to make sure that you specify the correct compiler options, for example. -rdynamic -ldlin the case of GCC.

0
source

Source: https://habr.com/ru/post/1735588/


All Articles