How are we able to create an array statically by passing n as variable? (pr array in the question )
How are we able to create an array statically by passing n as variable?
Hey, i didn’t exactly get ur ques. Can u explain ur doubt
Generally we don’t create array like the way it was created in video. We want the number of elements upfront but in the video we have used pr[n+1] where n is taken as input from main function. Then how this didn’t give compile time error?
Basically input of n is being taken and then being passed to sieve function… hence it doesn’t give any error…
But the n would be taken at runtime. If this doesn’t give error then why can’t we write the same in main function? We should be able to do it?
Yes if u don’t want to call function u can directly do the same thing in mail function also… just copy that code( in sieve function) in main…
But my question is how are we able to do this? We can’t create array of n elements that’s why we had vector in picture.
i am unable to understand what u mean by We can’t create array of n elements… off course we can make array of size n
As far as I remember earlier we were not able to create an array like this we go for dynamic allocation if we have to pass variable to it, not sure if this has changed.
no, creating array normally or through dynamic allocation is same only…
ok, thanks a lot for your response
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.