edit: fixed an error in test Question #1
So, yet another fall career fair has gone by, but this year’s turnout seemed a bit…well…crappy (for computer science, at least). A few of the bigger players were there (Microsoft, nvidia), but most companies were small New York companies that just wanted college students because they can’t afford to pay real people.
I went to the nvidia booth, and, lo and behold, found the guy who interviewed me last year. I saw him after the interview (ironically, getting on a plane to Seattle to interview with Microsoft), and so we’ve talked relatively extensively on topics like software development, career paths, Microsoft (he was the technical lead of directx 5 or 6, I forget which), and nvidia. I joked around with him and another guy working the booth, showed him my resume, and took another one of the (infamous!) nvidia tests. He gave me the hardest one, which was exciting. It looked something like this:
Question #1: What is different about these two segments of code?
a)
int Clocks(unsigned short* p) {
int val = *p;
val |= (*p << 16);
return val;
}
b)
int Clocks(volatile unsigned short* p) {
int val = *p;
val |= (*p << 16);
return val;
}
Question #2: What is wrong with the following code segment?
char* SaveString(const char* s) {
char* p = (char*)malloc(strlen(s));
while(*s)
{
*p++ = *s++;
}
*p = 0;
return p;
}
Question #3: Write atoi. Ignore all leading and trailing non-numeric characters,
e.g. "abcd1234defg" will return 1234. If no number can be read, return a -1.
Ignore all '-' characters (no negative numbers), and assume the conversion
will not overflow.
int atoi(char* s) { ....
I’ll post some solutions later in the week. Oh, he originally gave me a different test, but the last question was the same from the test I took last spring (count the number of on bits in an integer), and I didn’t feel it was honest for me to take it again. That test just had a few questions like:
Question #1: unsigned short a = 0xa3b7 unsigned short b = 0x3f4c show the results of: a + b a & b (I forget what the second question was).
I’ll also post an answer for the “count the number of on bits in an integer” with the other solutions. It’s a fun little problem, and kudos to Sidney Marshall for showing me a few nice ways of doing it.