Question:
Is the following valid code? If so, what does it print?cout << (int *) “Home of the jolly bytes”;
Answer:
Ye s , it is valid.The expression "Home of the jolly bytes" is a string constant; hence it evaluates as the address of the beginning of the string.The cout object interprets the address of a char as an invitation to print a string, but the type cast (int *) converts the address to type pointer-to-int, which is then printed as an address. In short, the statement prints the address of the string, assuming the inttype is wide enough to hold an address.
0 Questions:
Post a Comment