set_intersection of two sets

set_intersection - C++ Reference

has an example of finding the set_intersection, but it declares the intersection set as

why exactly we need to specify the memory, as I know vector is dynamic array, this works fine even when I don't specify for smaller set intersection but when the intersection comes out to be bigger it shows segmentation fault, How to fix it without killing the dynamic property of the vector, or is there any better way to find set intersection, its better for us to use STL library if am not wrong.