## Alcatel Lucent Interview Question for Software Engineer / Developers

• 0

Country: India
Interview Type: In-Person

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

char dummy[10]; // X is data type of unknown size
int size=(X *)dummy[1]-(X *)dummy[0];

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

cout << (size_t)((X*)0+1) << endl;

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

1. Declare array of the type X of size 2
2. subtract address of 1st elemement x[0] from 2nd element i.e. x[1]
this will give you size of X

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

Almost, first convert the two pointers to char *, otherwise you will get 1 (this is how pointer arithmetic works)

X array[2];
char *first = (char*)array; // which is &array[0]
char *second = (char *)(array+1) // which is &array[1]
return second - first;

This works because sizeof (char) is defined as 1, and it is one of the very few implementation dependent type sizes in C.

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

The solution violates "without declaring a variable".

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

The solution violates "without declaring a variable".

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

Well, one could argue that an array of type X is not a variable of type X. One could counterargue, however, that creating an array of type X implicitly creates a pointer to type X.

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

But I can't think of any other solution either.

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

Create an array of two elements, subtract the addresses of second element from first element. Working code:

``````#include <iostream>
class X{
public:
int i;
int j;
bool k;
int l;
int q;
int* n;
double* m;
};

int main(){
X A[2];

std::cout << size << std::endl;
}``````

if you don't reinterpret cast, size would always give 1 due to pointer arithmetic.

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.

### 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.