why in this code i am getting seg fault
Religious people
@dakshi
Segmentation fault is a specific kind of error caused by accessing memory that βdoes not belong to you.β Itβs a helper mechanism that keeps you from corrupting the memory and introducing hard-to-debug memory bugs. Whenever you get a segfault you know you are doing something wrong with memory β accessing variable that has already been freed, writing to a read-only portion of the memory, etc. Segmentation fault is essentially the same in most languages that let you mess with the memory management, there is no principial difference between segfaults in C and C++.
you can read more abt it here
refer to this code