Now how can i again write given binary file obj_pattern.bin with some new values of ad[i] in another program. For example in first program i put ad[] values in the file as 1,2 now how can i again write that same file without deleting the previous saved values 1 and 2?
Otherwise you're stuck with reading the data up to the insertion-point into a buffer, add the new data at the buffer, then continue reading from the original file to the end of that same buffer. When it's all stored in said buffer, output it back to the original file. (Large files can be handled with skillful use of buffers, append, and seekg/tellg).
--- To be safe you should actually write the buffer to a new file, then rename it as the original file just in case the program crashes half way through writing.