The address of character type variable

后端 未结 3 753

Here is just a test prototype :

#include 
#include 
using namespace std;

int main()
{
   int a=10;
   char b=\'H\';
   string          


        
3条回答
  •  一个人的身影
    2021-01-20 11:36

    There is an overload for << which takes a pointer to char and interprets it as a terminated C-style string. Using this for the address of any other char will go horribly wrong.

    Instead, convert to a typeless pointer so that << doesn't get too clever:

    cout << static_cast(&b)
    

提交回复
热议问题