+ 3

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

1st Apr 2020, 6:51 AM
Aman Jain
Aman Jain - avatar
3 Answers
+ 2
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.
2nd Apr 2020, 6:27 AM
Asha Malla
Asha Malla - avatar
+ 1
Or you can use while or do-while loop too.
2nd Apr 2020, 9:47 AM
Asha Malla
Asha Malla - avatar
0
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.
2nd Apr 2020, 9:46 AM
Asha Malla
Asha Malla - avatar