0

How many locations in the memory

int x[n] will reserve how many locations in the memory? n or n+1

24th Apr 2020, 1:59 AM
Mohamad Alkaleeh
5 Answers
+ 2
What do you mean by location? As far as I know, lets say you have 4gb of ram, when computer is running some of it will be reserved for OS. Lets say you are left with 3.5gb of ram. You allocate memory for your variables, when you run the code, there will be memory allocated for your variables in ram. So here, I think, we cannot talk about a physical location. If you want to know the amount of memory that will be allocated for your variables, use sizeof() function. It takes data-type (like int, char or user defined), variables (arrays, vectors whatever) as parameter and returns size in bytes.
24th Apr 2020, 2:07 AM
Mustafa K.
Mustafa K. - avatar
0
Thanks i agree with you but There is a question https://www.sololearn.com/post/350359/?ref=app is the correct ans n-1 ?
24th Apr 2020, 2:44 AM
Mohamad Alkaleeh
0
I think it is n because every element's address is different. If there are n elements than there are n different addresses (locations). Why would it be n-1?
24th Apr 2020, 10:07 AM
Mustafa K.
Mustafa K. - avatar
0
Mustafa K. Because it's array and it starts from zero so I tought n-1 but know as you said the correct answer is n
24th Apr 2020, 10:13 AM
Mohamad Alkaleeh