NVIDIA Interview Question for Interns


Team: System Software
Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
4
of 8 vote

To implement integer array of size array_size
int *p = (int *) malloc (sizeof(int) * array_size);

now you can assign values using p[i] = something // i =0 to array_size-1
and and access them using same;

- Punit Jain May 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

array is not thr, so u cant use p[i] notation, instead you can use *(p+i) notation.

- kim July 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

in place of p[i] we use *(p+i)

- navya July 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

p[i] is same as *(p+i) so u can use either...

- pr6989 September 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How to free this piece of memory?

- patric.zhao January 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Its simple.. free (p) will do the job

- Punit Jain January 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes. Actually, my question is when we free it.

The array would be freed when out of scope. So we have to do this manually when exceed the scope,right?

- patric.zhao January 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, we will have to free it manually when we are done with it.

- Punit Jain January 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

having continuous memory allocated to a pointer and moving the pointer

- Anonymous May 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

just use alloca for that to allocate the memory, because as the function ends it will automatically deletes the memory

- Anonymous February 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

very concise answer, I like it!

- 1 May 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your are funny dude..(assuming you were the one who commented on the other question too) do you always go to each question and say its a stupid question? There is a difference between 'simple' pointer to a memory and an array. Do a sizeof operator on an array and a 'simple' pomoter to a memory.anyway this is not relavant to this question..

2 things that an array gives that i can think of is memory space and random access. We can get memory space from malloc. For the random access since we dont hv the compilers help we will not be avle to use [] operator. We will have to implement a function which will do pointer arithmetic and give the value at a gicen poisiton. So instead of a[10] we will be calling get_value(a,10), here a is the pointer to the malloced space.

Ofcourse there will be a question of freeing the memory space and stuff. We should thank the compilers for having given us array..

- Anonymous May 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

nope, dude, I do not write for each question: only for those which are stupid ))

what you said is right but well operator [] is a syntactic construct to do pointer arithmetic, It has nothing do to with a "data structure", e.g. you can write a[10] and 10[a] which are the same for compiler.
On a similar note, you can implement sizeof operator using pointer to char*

oh mighty compiler thanks for giving us an array ))

- ? May 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@eugene.yarovoi got you the first time :)

- Anonymous June 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks for the first reply to this comment, that mostly answers the question as well.

- chandan.jc September 26, 2012 | Flag


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