Saturday, April 19, 2014

Imagination

Another thing from my diary. Hope you like it.
"A person who can count the leaves of a tree out of some seed that needs to be planted yet, is far better than the one who needs ages to find the right seed to plant a tree."

Wednesday, April 16, 2014

Object Size Tweak

Someone asked me a few days ago about an interview question. Make a function that returns the integer containing the size allocated to that object passed in that function as a parameter. In simple language, put same functionality as sizeof operator present in C++.

So I answered him to use character pointer to look through the number of bytes allocated.
This function simply does pointer arithmetic, and then simply subtracting the starting address of object from one-block-ahead pointer gives the exact number of bytes.

Happy learning!

Monday, April 14, 2014

Fun With Mathematics

Found some mathematical tricks from an awesome mobile application. Happy learning.

Square a two-digit number ending in 5:
For this example I will elaborate using 45. Try doing it with the numbers ranging from 15 to 95 all. You’ll have fun if you’re into mathematics. At some point in life you might be the smartest sheep in herd.
Let’s see the trick.
  1. Take the tens part of the number (in our case it is 4 from “4”5).
  2. Add one to it (that makes it 5 = 4 + 1).
  3. Multiply the result with the tens part (original tens part, that’s 4, so 4 x 5 = 20).
  4. Append 25 at the right of the resultant (20 25 = 2,025).
  5. Use your calculator and compare result.
Will keep posting more, I hope you learned something new.