今日、いくつかの奇妙な動作を観察しました。コードは次のとおりです。
コード :
#include <iostream>
struct text
{
char c;
};
int main(void)
{
text experim = {'b'};
char * Cptr = &(experim.c);
std::cout << "The Value \t: " << *Cptr << std::endl ;
std::cout << "The Address \t: " << Cptr << std::endl ; //Print weird stuff
std::cout << "\n\n";
*Cptr = 'z'; //Attempt to change the value
std::cout << "The New Value \t: " << *Cptr <<std::endl ;
std::cout << "The Address \t: " << Cptr << std::endl ; //Weird address again
return 0;
}
質問 :
1.) 私が持っている唯一の質問は、なぜcout theAddress
上記のコードで奇妙な値が出てくるのでしょうか?
c
2.)奇妙なアドレスを持つポインタを逆参照することで、メンバーの値を変更できるのはなぜですか?
ありがとうございました。