It's UWAweek 38 (2nd semester, week 8)

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying the 3 articles in this topic
Showing 3 of 487 articles.
Currently 21 other people reading this forum.


 UWA week 35 (2nd semester, week 6) ↓
SVG not supported

Login to reply

👍?
helpful
5:51pm Mon 26th Aug, Krish J.

I had a doubt in calculating the new value of 'p', when the operation of ++p or --p is performed. So this operation signifies that another consecutive element of the array is accessed. But what if the other element occupies the space greater than or less than 4 bytes?? Is that even possible or not??


SVG not supported

Login to reply

👍?
helpful
6:51am Tue 27th Aug, Christopher M.

"Krish Jasani" <23*1*3*8@s*u*e*t*u*a*e*u*a*> wrote:
> I had a doubt in calculating the new value of 'p', when the operation of ++p or --p is performed. So this operation signifies that another consecutive element of the array is accessed. But what if the other element occupies the space greater than or less than 4 bytes?? Is that even possible or not??
I can't quite understand the 2nd part of your question. If p is a pointer of type T, the incrementing or decrementing of p will increase or decrease its value by sizeof(T). The sizeof(T) is not always 4 - it literally depends on the amount of memory required to store one instance of T, and it may be 1, 2, 4, 8 .... (or other values if T is not a base-type but a user-defined structure). p doesn't 'know', and can't check' that it is actually pointing at memory holding a T. If p is decremented to an address that is 'before' the beginning of an array, there are no guarantees that the memory before the array is storing a T, and so p may point to a location that is not of type T. Hope this helps,


SVG not supported

Login to reply

👍?
helpful
11:28am Tue 27th Aug, Krish J.

Thanks Chris, understood.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy