Tricky C++ questions

Started by
24 comments, last by ZQJ 17 years, 1 month ago
1. How do you add with out using addition, subtraction, modulus, multiply, divide operators.
unsigned char add(unsigned char a, unsigned char b){	for (int i = 0; i < b; i++)		++a;	return a;}


stupid way to add, but it does satisfy the requirements.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Advertisement
Quote:Original post by daniel_i_l
Thanks for all the ideas!
I just finished a few hours ago and they didn't really ask anything hard. the "hardest" thing that they asked was "what's the difference between overloading and overwriting":)


What is this overwriting you speak of.


>int a =1;
>std::cout << (++a + ++a + ++a) << std::endl;
Questions like that might be interesting - but (together with all
the really low-level questions) they are unsuitable for an interview.
Most of them are 'gotcha' questions and it's really unfair to do that
to a nervous applicant - you should try to make an honest impression
of if the person is up to the job.

Besides that, whoever would use stuff like that (without detailed
comments) in real-life production-code should NOT get the job.

Just my 2ct.
visit my website at www.kalmiya.com
Quote:Original post by MilfredCubicleX
Quote:Original post by daniel_i_l
Thanks for all the ideas!
I just finished a few hours ago and they didn't really ask anything hard. the "hardest" thing that they asked was "what's the difference between overloading and overwriting":)


What is this overwriting you speak of.


He probably meant overloading and hiding.
------------------------------Support the Blue Skies in Games Campaign!A blog... of sorts.As a general rule, if you don't have a general rule in your signature, you aren't as awesome as someone who does. General rules roxor teh big one one ones.
Quote:Original post by programwizard
Quote:Original post by MilfredCubicleX
Quote:Original post by daniel_i_l
Thanks for all the ideas!
I just finished a few hours ago and they didn't really ask anything hard. the "hardest" thing that they asked was "what's the difference between overloading and overwriting":)


What is this overwriting you speak of.


He probably meant overloading and hiding.


Or possibly overloading and overriding. I have been asked that question in an interview before.
So the interview questions of today are limited to low-level jabbering? No questions about inheritance versus composition, design patterns and such?

I mean, I can understand why such hidden-gem questions can be usefull, it's one way to see who's actively developing him/herself and who isn't, but I'd say it's just one side of the equation... or perhaps better said, one of many facets. :)
Create-ivity - a game development blog Mouseover for more information.
Well, a slightly more efficient addition algorithm, for no particular reason other than I'm bored:

int add (int a, int b){  while (b != 0)  {    int x = a ^ b;    int y = a & b;    a = x;    b = y << 1;  }  return a;}


Oh, and before somebody points this out, I'm aware it's twos complement only and therefore not standard compliant.
Quote:Original post by Captain P
So the interview questions of today are limited to low-level jabbering? No questions about inheritance versus composition, design patterns and such?

I mean, I can understand why such hidden-gem questions can be usefull, it's one way to see who's actively developing him/herself and who isn't, but I'd say it's just one side of the equation... or perhaps better said, one of many facets. :)


At the last game-dev company I was interviewed for, the first interview consisted of a 1hour exam on on this jabbering, then the second interview was on design patterns, the third interview was on character/personality.

This topic is closed to new replies.

Advertisement