reason for dynamic array,why can’r we take a static array.
String tokenizer-2
Hey Utsav, that’s because dynamic arrays are created on heap memory and static arrays are created on stack memory, so you will not able able to return a static array as it will be destroyed from the stack memory when called function is fully executed.
Hey Utsav, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “Ask Doubt” section, when your doubt is resolved.
static variable are store on stack or data segment?
if it will be stored on stack ,how its lifetime will be throughout the life of the program.
and also
#include
using namespace std;
char * vi(){
static char c[]=“vipin”;
return c;
}
int main() {
cout<<vi();
return 0;
}
this program is working fine .
I think we are using dynamic array only because we not know the size of the tokens.