Unable to understand the execution of the code !! How char to char is subtract?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Unable to understand the execution of the code !! How char to char is subtract??

https://code.sololearn.com/cb73u46026OL/?ref=app

18th Jan 2020, 4:05 PM
Lazy_codeR.04
Lazy_codeR.04 - avatar
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
18th Jan 2020, 4:40 PM
你知道規則,我也是
你知道規則,我也是 - avatar
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.......
18th Jan 2020, 5:57 PM
Lazy_codeR.04
Lazy_codeR.04 - avatar