Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psuedo global variable in c

An interview question asked very frequently. But, i'm not clear with the explanation, which i found on different websites. Because, when i'm trying to execute this code, then it shows _AX undeclared error.

main()
  {
   int i;
   i = abc();
   printf("%d",i);
  }
  abc()
  {
   _AX = 1000;
  } 

people says _AX is the pseudo global variable, that's why it shows output 1000.

*Note : - It showing error _AX undeclared, but when i declared the variable, then it shows some garbage value *

like image 219
Ravi Avatar asked Feb 19 '26 03:02

Ravi


1 Answers

This comes up frequently? It's utter nonsense. Presumably _AX is some compiler-specific notation to access the "ax" register, which is used on x86 for return values. However there's no reason to believe the value in the register should not get clobbered between the assignment and function return. This program is invoking undefined behavior. If somebody offering you a job expects you to know such invalid practices, RUN. FAST. They're not competent.

like image 88
R.. GitHub STOP HELPING ICE Avatar answered Feb 21 '26 17:02

R.. GitHub STOP HELPING ICE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!