Alcatel Lucent Interview Question for Software Engineer / Developers


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];

- Abhi February 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

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

- Anonymous February 02, 2012 | Flag Reply
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

- dongre.avinash February 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- Selmeczy, P├ęter February 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The solution violates "without declaring a variable".

- Saurabh February 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The solution violates "without declaring a variable".

- Saurabh February 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- eugene.yarovoi February 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

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

- eugene.yarovoi February 02, 2012 | Flag
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];
	size_t addr1 = reinterpret_cast<size_t>(&(A[1]));
	size_t addr0 = reinterpret_cast<size_t>(&(A[0]));
	size_t size = addr1-addr0;
	
	std::cout << size << std::endl;
}

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

- barcod February 02, 2012 | 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