Microsoft Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

typedef enum{false, true} bool;

int __atoi__(const char *str)
{
        bool isNeg = false;
        if(str[0] == '-')isNeg = true;
        int result = 0;
        int len = strlen(str);
        int i;

        for(i=isNeg; i<len; i++)
        {
                int digit = str[i]-'0';
                if(isNeg)
                {
                        if(result <(INT_MIN+digit)/10)return INT_MIN;
                        else result = result*10-digit;
                }
                else
                {
                        if(result > (INT_MAX-digit)/10)return INT_MAX;
                        else result = result*10 + digit;
                }
        }

        return result;
}

- Guess Who?? March 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Answer to last part

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{
    string a="3";
    string b="65";
    int sum=atoi(a.c_str())+atoi(b.c_str());

    char Ssum[sizeof(sum)];
    itoa(sum,Ssum,10);
    string s=Ssum;
    cout<<s;
    int d;
    cin>>d;
    return 0;
}

- Dhawal February 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry the last 2-3 lines are not required :)

- Anonymous February 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sorry, the last part was multiply instead of add.

- Anil February 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ya i think it will still work

- Anonymous February 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

ya i think it will still work

- Anonymous February 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef enum{false, true} bool;

int __atoi__(const char *str)
{
        bool isNeg = false;
        if(str[0] == '-')isNeg = true;
        int result = 0;
        int len = strlen(str);
        int i;

        for(i=isNeg; i<len; i++)
        {
                int digit = str[i]-'0';
                if(isNeg)
                {
                        if(result <(INT_MIN+digit)/10)return INT_MIN;//Underflow. So return Min. int value...
                        else result = result*10-digit;
                }
                else
                {
                        if(result > (INT_MAX-digit)/10)return INT_MAX;//Overflow. So return Max. int value...
                        else result = result*10 + digit;
                }
        }

        return result;
}

- Guess Who?? March 26, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More