Interview Question: String Theory (the C++ Kind, That Is)

Sample Question #79 (programming – C++)

First, assign the string "xerox" to a string variable q (without the quotes, of course). Next, change the first "x" to upper case, but without modifying q itself. What to do?

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

2 Responses to Interview Question: String Theory (the C++ Kind, That Is)

  1. Brett says:

    ANSWER
     
    This will work:
     
      char q[] = "xerox";  char* p = q;  p[0] = ‘X’;
    The answer actually isn’t "obvious," because string operations in C++ are tricky! If you got it right, pat yourself on the shoulder and buy yourself an ice cream bar. 🙂

  2. Zhihua says:

    It seems not right. q is changed since p is  a pointer.

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