8:47 the reason why -4 was printed is because anything allocated with malloc is aligned to a boundary that is suitable for all fundamental objects. Also, when you subtract pointers you get a value of type ptrdiff_t which is guaranteed to always be able to hold any pointer difference.
@joseluisdominguezplaza6839 Жыл бұрын
Yeah I tried with an array of long long and had a different result (-1) that I think is the correct result
@mavrix23564 жыл бұрын
Amazing explanation 👌
@novaz4768 Жыл бұрын
it wouldve been helpful to give us a work around. I was trying to add refrenced variables in a function
@CodeVault Жыл бұрын
For what do you need a workaround exactly? Can you explain more in detail so I understand what you need?
@devDarshilJadav4 жыл бұрын
thank you so much
@krtirtho9 ай бұрын
I wish u were my professor
@ayonsinha20753 жыл бұрын
Sir u r are amazing ....💥🔥...where are from sir ??
@CodeVault3 жыл бұрын
Thank you! I'm from Romania
@m.a28942 жыл бұрын
Hello, can you tell me why does my program returns '1' when I write it like this: int main() { long long int a = 15; long long int b = 20; long long int c = 30; long long res = &a - &c; printf(" %d\t%p", res, &res); } but returns '2' when i write it like this: int main() { long long int a = 15; long long int b = 20; long long int c = 30; printf("%p
@CodeVault2 жыл бұрын
Huh, I am stumped as well. The only way to find out is to start looking at the differences in the assembly file. I'm sure there's something that happens there
@nero2k6192 жыл бұрын
I guess its because &b has to pushed onto stack but when you try to comment out printf("%p
@martingeorgiev999 Жыл бұрын
In the first case 'b' does not exist. The compiler is free to remove any junk from the code as long as it does not change the observable behavior.
@mukteshgautam40506 жыл бұрын
It adds 8bits not 8 bytes!
@CodeVault6 жыл бұрын
The data type is a long long which is stored on 8 bytes. Adding any number to a pointer to long long would add that value times 8 bytes to the pointer. Remember, 1 byte = 8 bits. Not the other way around