I'm having trouble understanding what the output would be
int main( ) {
int x = 5, y = 10, z = 20;
int *ptr1 = &x, *ptr2 = &y, *ptr3 = &z;
*ptr2 = *ptr3 + *ptr1;
ptr2 = ptr1;
*ptr2 = *ptr3;
printf("%d and %d and %d\n", x,y,z);
/*char str[] = "Stackoverflow is kind.";
int len = strlen(str);
printf("%s and %d\n", str, len);
char *p;
p = str;
printf("%c and %c and %c and %c\n",
*p, str[3], *(p+9), str[len-2]);*/
return 0;
}
Would the first addition line even be allowed? I thought you couldn't add pointers. And what would the difference be between these 2 lines?
ptr2 = ptr1;
*ptr2 = *ptr3;
Obviously they are different pointers, but how do they function differently?
I've ran the program and got 20 25 20 but I don't understand how