r/AskComputerScience • u/LivingExpress3970 • Feb 24 '26
Doubt regarding array
So i have started learning array since day before yesterday and a question is bugging me. I have not asked this question to anyone as they would think me as dumb (which i am). Here is the question.
Why do everyone say we need to create new array of more size if array fills up? Couldn't we just edit the size?
For example if int arr[4] is defined but we need to add a fifth element, couldn't we just edit out 4 to 5 in code itself and run it again?
I know the question is stupid but it doesn't make sense to me. This is my first time doing C. Previously i have only learned python. So please help me.
View all comments
Show parent comment
1
u/Qwertycube10 Feb 24 '26
Just to add to this, in the third case a clueless user would just cause a crash, however a malicious user would be able to overwrite the next thing in memory with malware, making that kind of unchecked buffer access a major security vulnerability.