Skip to main content
Disha
Associate II
September 3, 2020
Question

pointer typecasting

  • September 3, 2020
  • 1 reply
  • 901 views

As per image sub=7(not typecasted), sub1=28(typecasted). I don't understand why is sub giving wrong value I understand I have not typecasted but,each pointer variable is holding 4 byte value (i.e int type) then,typecasting must not be required isnt it? where am I going wrong?

0693W000003QfNyQAK.png

    This topic has been closed for replies.

    1 reply

    hs2
    Visitor II
    September 3, 2020

    The difference of int pointers (pointers to ints which are 32 bit wide for a 32 bit processor) is counted in ints.

    As defined by the C standard regarding pointer arithmetic.