C Puzzle - 1


For the following code:

int fun()
{
     /*Write Code Here*/
}

int main()
{
     int i=10;
    fun();
    printf("%d\n",  i);
    return 0;
}


Now we have to change the value of i from 10 to 20 without changing anything in main(), we have to write all the operations in the fun() function.

Logic is that local variables are stored in the stack and stack always grows in downwards.

int fun()
{
   int j;
   int *ptr=&j;
   while (*ptr != 10) ptr--;
   *ptr =20;
    return 0;
}

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto