Microsoft Interview Question for Software Engineer / Developers






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

4 issues

(1) no return value. ( should return a char - as the method name suggests so).
(2) Cannot assign a char to string variable
(3) no error checking for incoming string ( what if s is null?)
(4) if we need 3rd char of the string, we should check if the string has atleast 3 chars.

- morpheus February 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Hi buddy s above query is compiler error because "s" is not string array.

- Bharath February 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I corrected it as
public int getchar(string s)
{
if(s!=null)
if(s.length()>4)
char c=s[3];
}

- Guest May 30, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No return code?

- Anonymous June 18, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

public int getchar(string s) {
.....int returnValue = -1;
.....if(s == null) return returnValue;
.....if(s.length() >= 4) {
..........char c = s[3];
..........returnValue = (int)c;
.....}
.....return returnValue;
}

- FK October 02, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Unnecessary creation of temporary int object called return value. You don't need that.

- Aditya October 11, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int getchar(string s)
{
string s1=s[3]; // the error is: can not implicitly convert a char to string
return 0; /// and this needs a return value
}

- ming.huo August 21, 2008 | 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