Samsung Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

As we know members of struct are public by default, lets implement the private access specifier behavior into the struct.

In the below samplestruct example, If you provide a samplestruct* create_struct() method as an interface to client and a series of methods that operate on samplestruct*, hiding the actual definition of samplestruct from the client, then a similar effect is achieved.

// File "samplestruct_private.h"

struct samplestruct {
    int priv_int;
    char priv_char;
};

// File "samplestruct.h"

typedef struct samplestruct samplestruct;
samplestruct * create_struct(int a, char b);
int mangle_struct(samplestruct *);

// file "samplestruct.c"

#include <stdlib.h>
#include "samplestruct.h
#include "samplestruct_private.h"

samplestruct * create_struct(int a, char b) {
    samplestruct * s = (samplestruct *) calloc(1, sizeof(samplestruct));
    s->priv_int = a ;
    s->priv_char = b ;
}    

int mangle_struct(samplestruct *s) {
    return s->priv_int + s->priv_char;
}

Distribute samplestruct.c compiled into a library, along with samplestruct.h.

The functions declared in samplestruct.h form the public interface of a type, but the internal structure of that type is opaque.
In effect, the clients who call create_struct() can't access the private members of the samplestruct object.

- R@M3$H.N December 31, 2014 | 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