Why the entire string is displayed as outcome? Why address of 1st character not getting printed? How can I print address of 1st character? Please help me.
#include <iostream>
int main()
{
char x[6]="hello";
std::cout<<&x[0];
}
The <<
operator on std::cout
will treat a char*
as a null-terminated string. You will need to cast it to a void*
to print the pointer value.
Try this:
#include <iostream>
int main()
{
char x[6] = "hello";
std::cout << static_cast<void*>(x);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments