Not really weird but interesting. The fact is, when we declare a function in C we can use "..." in the arguments to be able to get any number of any type of variable. In fact it is used in printf() and scanf(), and this gives bird to some interesting behaviour, for instance the code: int main() { int a,b; printf("\nEnter two integers numbers:\n",&a,&b); scanf("%d %d"); printf("%d %d\n",a,b); return 0; } will print something like: Enter two integers numbers: 1 2 1 2 but how does scanf() knows I want to get those number at a and b? Those the printf() tells it to? I mean, I did sent the addresses of a and b to the printf() function so maybe it can tell the scanf() about it, right? Well, wrong, the truth is much simpler. The way a function in C works is by first transferring the values of the arguments into a special memory place and then jumps in to the function code itself. So first ...
Comments
Post a Comment