Microsoft Interview Question for Software Engineer / Developers






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

char *strcat(char *dest, const char *src)
{
    size_t i,j;
    for (i = 0; dest[i] != '\0'; i++)
        ;
    for (j = 0; src[j] != '\0'; j++)
        dest[i+j] = src[j];
    dest[i+j] = '\0';
    return dest;
}

- Anonymous May 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

we have to make sure new string won't overwrite source string

char* mystrcat(  char*t,char*s)
{
	char* tmp=t;
	int sizet=strlen(t);
	if(s==NULL) return NULL;
	if(t==NULL) return s;
	if(s-t<=sizet+strlen(s)+1) return NULL;
	while(*(t+sizet++)=*s++);
	return tmp;
}

- Charles December 31, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi Anonymous,
First you have to allocate memory for the src string that would be concatenated to the destination string.

- Abhishek July 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char *myStrcat(char *s, const char *t)
{
char *p = s;

if (s == NULL || t == NULL)
return s; /* we need not have to do anything */

while (*s)
s++;

while (*s++ = *t++)
;

return p;
}

- aditya.bokaro August 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char * mystrcat(char* s1,char* s2)
{
while(*s1)
s1++;
while(*s2)
*s1++=*s2++;
return s1;
}
}
int main()
{
char*s1="rajnesh",*s2="kumar";

printf("%s",mystrcat(s1,s2));
}

- Rajnesh March 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

core dump

- sanjay October 17, 2014 | Flag


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