Depends on your architecture.
Suppose, for your processor, the int type is 32 bits long. And suppose that an memory address is 64 bits long (for example, on x86-64 mode on Intel/AMD processors).
That expression in your example will strip the upper 32 bits of var_ptr (because of the int casting) and add the resulting value to val2, assigning to val1.
Take a look in this example:
Code:
/* test.c */
#include <stdio.h>
int main( void )
{
int val1, val2, val3;
void *p, *q;
val3 = -1; // all bits 1
p = main; // p is the address of main.
val1 = val3 + (int)p; // strip upper bits from p.
val2 = val3 + p; // promote val3 to (long),
// but strip upper bits on assignment.
q = p + val3; // promote val3 to (long).
// no stripping.
// using "%lx" because I know a ptr and a long are the same size
// on x86-64.
printf( "%x, %x, %lx\n", val1, val2, (long)q );
}
Compiling and linking:
$ cc -o test test.c
test.c: In function ‘main’:
test.c:11:17: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
val1 = val3 + (int)p; // strip upper bits from p.
^
test.c:13:8: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
val2 = val3 + p; // promote val3 to (long),
^
$ ./test
74b40649, 74b40649, 563f74b40649
Notice the 0x563f00000000 difference and the warnings?
In x86-64 the pointer types have 64 bits. But other architectures can use different sizes for pointers and int.
If you want to deal with integers and pointers this way you can use the intptr_t (or uintptr_t) defined in stdint.h. You won't get rid of the warnings, but it is garanteed not to have these side effects on the results (the size of intptr_t and a pointer are the same).
But, be warned: the size of a pointer can be smaller then of an int as well... depends on the processor!