Interview Question: Strange Cast

Sample Question #9 (programming – C++)

Is the following valid C++ code? If so, what does it print?

  cout << (int *) "Home of the jolly bytes";

[Taken from chapter 4 of Prata, C++ Primer Plus (5th ed.)]

Advertisements
This entry was posted in Sample Qs. Bookmark the permalink.

4 Responses to Interview Question: Strange Cast

  1. Wu Chao says:

    I just find it is interesting when we change "int" to "float, double, string", we have the same output.

  2. Brett says:

    Don’t tell me you tried it out on a PC.  🙂

  3. Wu Chao says:

    I tried on PC. I want to check my answer is right or not. Then I want to check whether there is a difference when I change it to other data types. Too silly?

  4. Brett says:

    Of course it’s okay to confirm your answer on a computer… when you practice. 🙂  At interview time, though, you usually won’t be able to do that — although one time when I was interviewing at Goldman Sachs one guy put me in front of his PC and asked me to write a short program.  (I wrote the program right, and answered all the interview questions right that day, but still didn’t get the job in the end!  Must have been the big red tie and wrinkled pink shirt I was wearing that day…)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s