Why these codes take string greater than the array size and also print them ?

https://code.sololearn.com/cIXDoppKtYk1/?ref=app https://code.sololearn.com/cjNNIcZd69S9/?ref=app


4/1/2020 6:51:43 AM

Aman Jain

4 Answers

New Answer


asha malla so what we can use instead of %s so that it take only till maximum defined size of array. And, then why we define the maximum size of array if it has no use🤔


Here when you use %s or gets or puts, these work on pointers. They take variable or array as pointer. So, it doesn't care about what size you mentioned in declaring array. So, it prints everything which is given as input.


Or you can use while or do-while loop too.


Then we can use a for loop and access specifier %c or get() or put() and iterate till your size of array. It takes one character at a time.