Student Interview Question for Software Engineer in Tests


Country: India
Interview Type: Written Test




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

Most of the Time size of the structure is not equal to the sum of the size of all its elements.It is because of Padding Space added to the element with respect to the largest element.
Example:

struct X{
double d;
char c;
int i;
};

In the above question size of the structure is 16 bytes.
Here size of largest Element is 8 bytes.
when another element comes another slot of 8 bytes is allocated and then a character element takes 1 bytes and integer takes 4 bytes.In this slot, 3 more bytes are remaining if other elements came which size is less than or equal to 3 bytes allocated to that slot otherwise another 8 bytes slot is allocated.

- kamleshbhalui September 07, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

please go throw structure padding you will come to know whats happening in memory

- mahesh October 21, 2020 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Double - 8 bytes
char - 1 byte
int - 4 bytes

Total size will be 13 bytes. 13 bytes + 3 bytes (structure padding) = 16 bytes (Mutiple of 4 (Word size in byte in 32-bit machine)).
Answer : 16

- Giriprakash November 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think answer is 11 because double is 8 bytes and char is 1 byte and int is 2 bytes am I correct or not am I wrong why wrong tell me please

- Anonymous September 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Depending on the architecture definitions of double, int, etc.... each member is a different value potentially but let's assume a 32bit architecture:
double = 4Bytes
char = 1 Byte
int = 4 Byte

The structure isn't listing any option for packing and you cannot access (unless you have a funny architecture that allows it) access of doubles or ints on a non-word alignment (0,0x4, 0x8, 0xc). I believe the answer will be 12 Bytes.

in interviews easiest is to say " it depends" and ask about the architecture being used.

- Anonymous October 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you are wrong.Size of structure is depend on largest data type and order of the string data type.In the same qsn. if you write char,double and then int respectively then the size of string will be 24.

- brij October 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It depends on the 32/64 bit architecture and the padding.

- rajukanike November 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As my perception ans is, 13, bcz double =8 bytes , int = 2 bytes ,and ch= 1 byte,
and 2 bytes is allocates as padding space for Sturcture, so 11+2 =13, ans, If i am not wrong

- Abdul Manan September 09, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Answer is 16, in 32-bit OS, double takes 8 bytes, then ch 1 bytes and then 3 bytes are allocated for padding for structure, then integer 4 bytes, so 16 bytes.

- Vidya November 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Answer is 16, in 32-bit OS, double takes 8 bytes, then ch 1 bytes and then 3 bytes are allocated for padding for structure, then integer 4 bytes, so 16 bytes.

- Pri_VS November 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

answer is 4.

- Priyanshu Tiwari November 07, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

7

- Anonymous September 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

From my point of view, the answer will be either 11 or 13. Because the type of integer has two types of bytes 2 or 4 so it depends on that what type of integer we are taking for this question.
So please tell me is it correct or wrong.

- Prasad June 06, 2018 | 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