Quote Originally Posted by Punju
i did not get you can you elaborate please
You start off with n elements as the size of the array. If there are any duplicates, after removing them, the size of the array would surely be less than n, but you did not update the value of n, hence you get those "garbage values".

Quote Originally Posted by Punju
please do mention the line which needs to be included
It looks like you declared duplicate_elements as having a return type, but you did not actually return a value. You might as well return the new effective size of the array so that you can update n in main.

By the way, duplicate_elements doesn't sound like a good name for the function: it sounds like you're duplicating elements rather than removing duplicates. A name like remove_duplicate_elements or even more simply remove_duplicates would be better.