HCL Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




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

Would this work?

char a[] = new char[10];
int *b = (int *) a;

- houseUrMusic August 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why not:
char * a = new char[10];

- Anonymous August 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

You can't (safely) because int is generally of size 4 bytes (unless you're targeting some legacy 16bit CPU chipset).

int* vars = reinterpret_cast<int*>( new BYTE[10] );

Would be the way to do it but seriously, it's not something anyone should be doing unless they wish to wilfully corrupt the heap...

- notthewronganswer May 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bytesds on the size of integer.
If its 2 bytes
int[] a = new int[5];

- Naveen August 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Naveen, Thanks for the answer, but if "int" is of 4 bytes then how can we allocate?

- rasmiranjanbabu August 11, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use malloc function.

- rishav006 August 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can not say char is always single byte. Don't you like malloc() and static_cast to int*?

- MadhaviA September 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

please write in c program not CPP

- Narasimha December 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 4 vote

int *p = new int[10]; // Memory for 10 int allocated
int *p = new int(10);//Memory for only 1 int allocated and it initialised with 10

- Satveer August 11, 2013 | 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