0
Unable to understand the execution of the code !! How char to char is subtract??
2 Answers
0
I'm not really sure about it, but I think it's because between p2 and p1 are 20 bytes since an int is 4 and there are 5 ints between them. p2 - p1 == 20 bytes. And a char is 1 byte. So there are 20 chars between them which output 20. This is called "Pointer Arithmetic".
Again, "I am not really sure". What I think about is that it may not be safe. ;/
About pointer Arithmetic: https://www.tutorialspoint.com/cprogramming/c_pointer_arithmetic.htm
0
@CarrieForie
Thank you for ur try.....
but i m bit confused about ur assumtion
wt i understood by ur explianation is ..... its printing the size of characters between the p2 and p1 ! m i right ??
how it is considering the size of the int as char ??
i had also made a look over the results with different operators in line8 which is an error( error: invalid operands of types 'char*' and 'char*' to binary 'operator*') everytime except when it is subtraction.......