Segmentation fault in my code but I am not able to recognize it where it is.
Deepak and Primes
refer this
I know the alternate method but I want to know the error in my code.
ok let me debug ur code
The segmentation fault in my code is because of the for loop in main fn. It might helps you.
![]()
this was the error. u have not declared the vector properly
this is ur code. it is working perfectly now

On gfg vector is initialized in this way so why my initialization is wrong?

the use push_back function
ohh okay! My doubt is clear Thanks!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.