As Tedinoz explained in his comment to your original post, this turns out to be simple math. However, you can accomplish it with a single array formula.
Delete any formulas you have in D4:D.
In cell D4, place the following formula:
An array formula can process an entire range instead of just a single cell or value.
IF first checks to see if there is any value in each row of C4:C. If not, then the corresponding cell in D4:D is left null as well. Otherwise, your B4 date is bumped backward 1 day (to the last day of the previous month), to the number of days in each cell of C4:C is then added.
If you get an error or strange results when you use this formula, there are three likely causes:
1.) If you get a return of numbers in the 40000-50000 range, those are actually unformatted dates. Just format Col D as dates (Format > Number > choose a date format).
2.) You will get an error or unpredictable results further down the column if you currently have unrelated data in your sheet below where your C4:C numbers are. You only let us see a keyhole view of part of your sheet, so there isn't much more I can tell you without seeing more of your sheet in this case.
3.) You are in a non-US locale that uses semicolons instead of commas. In that case, simply change every comma in the formula to a semicolon.