It's working should be clear, anyways, I've included some comments here and there.
When adapted to C++, you could simply modify this code to store all the prime factors into a vector or something, for later reuse.
(in C, you can also do something equal, if you choose the appropriate data structure)

Some driver code is included, if you want the code to be run in test mode, you'll have to add the following line to the top of this program: #define TEST_DRIVER 1 .
This is my output when the program is run in test mode:

it makes an assumption that all odd numbers are prime numbers (d += 2) if I understand well... correct me if I am wrong...

It's the other way around. The function makes the assumption that all even numbers are not prime, which is a safe assumption given that 2 (the only even prime) is given special treatment. The d += 2 part of this algorithm is skipping over even numbers (excluding 2) because they're guaranteed not to be prime factors.

Yes deceptikon is right and in addition to that,you need not check till the number itself,just check till the sqaure-root of the number and store it in an array and accordingly print them in sorted order.