Deshaw Inc Interview Question
SDETsCountry: India
Interview Type: In-Person
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct c_t {
void (*f)(void);
} C1;
void hello(void) {
printf("Hello World !\n");
}
void *new(char *name) {
void *rtn = 0;
if(name) {
if (!strcmp(name, "C1")) {
rtn = malloc(sizeof(C1));
((C1*)rtn)->f = hello;
}
}
return rtn;
}
void delete(void *p) {
if(p) {
free(p);
}
}
int main(void) {
C1 *temp = new("C1");
if(temp) {
temp->f();
delete(temp);
}
}
- Anonymous December 08, 2016