-1
#include <stdio.h>

int main() {

    int arr [6] = {22,3,30,1};
    int * p = arr ;
    p++;
    int ** p2 = &p;
    int x = 50 &(** p2 );
    printf("\n\n%d\n\n", x);
}

Can someone explain what happens in the second last row? printf prints 2.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
nan0
  • 84
  • 1
  • 5

1 Answers1

2

x is assigned the value of 50 bitwise-and'd with the integer pointed to by the pointer pointed to by p2.

Or in other terms, it is bitwise-and-ing 50 and 3. 50 is in binary 00110010 where 3 is 00000011. The only bit that they both have a 1 in is the second-least-significant. Therefore, the result is 00000010, or 2.

Gold Dragon
  • 480
  • 2
  • 9