if we have char arr[] then why does cout<<arr; print the string and not the address as it was in the case of integers?
Problem related to strings
Hello @vipin.kumar,
-
In the documentation of C++, the cout<< has many overladed functional definitions. (You will learn about overloading in detail in Object-oriented module).
-
When it accepts the address of char type, the compiler instead of printing the address the variable prints the characters until it encounters a ‘\0’ character.
-
It works correctly for other types but operates differently for char type.
-
To overcome this, you can typecast it to some other type preferably void.
Example:
cout<<(void *)arr;
Hope, this would help.
Give a like, if you are satisfied.
1 Like