Apple Interview Question for Quality Assurance Engineers


Country: United States
Interview Type: In-Person




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

char * setEmpty(int len){
	if (0>len) return NULL;
	char * c = (char *) malloc(len+1);
	memset(c, 0, len+1);
	return c;
}

- D-Unit April 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

why do u need to set all elements 0 only setting 1st element would be still empty string
char * setEmpty(int len){
if (0>len) return NULL;
char * c = (char *) malloc(len+1);
*c= '\0';
return c;
}

- SDguy April 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include <math.h>
#include <string.h>


char * create(int len)
{
   char my_str[100]={' ', ' ', ' '};

   char *str= (char *)malloc(len+1);

   // just copy based on the length drop everything else
   strncpy(str,my_str,len+1);

   return str;
}


int main()
{

  char *str2 = create(2);
  printf("%s\n", str2);

  getchar();
  return 0;


}

- Ramzi July 30, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

or may be you can use calloc to assign memory it will initializes the string to 0 by default.

char * setEmpty(int len){
if (0>len) return NULL;
char * c = (char *) calloc(len+1);

return c;
}

- Anonymous May 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

calloc takes in 2 parameters: number of elements, size of each element. Therefore it should be:

calloc(1, len+1);

- Anonymous August 01, 2013 | 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