1

Why int* char d is not printing address of y whereas, c is printing memory address of a? #include using namespace std;

int main () {

int a = 2;   // Initialization of a
int b = 3;   // Initialization of b

char y = 'A';
char z = 'B';

int* c =  &a ;  // c pointing address of a
char* d = &y ;  // d pointing address of y

*c = 32 ;
*d = 'D' ;

cout<< *c <<" "<< *d << endl;  // d is  printing 'D'

cout<< c <<" "<< d << endl;  // d should print memory address instead of 'D'

return 0;
}
  • I should add though, that in you case the program has undefined behavior, because `d` doesn't actually point to a null terminated string, just a single non-null character. For details on why it is treated as a null terminated string, see linked duplicate. – user17732522 Feb 02 '22 at 12:15

0 Answers0