NVIDIA Interview Question


Country: United States




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

syntax error malloc takes only one argument.

- Anonymous January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yeahh I think the declaration needs to be char* buf = (char*) malloc(10 * sizeof(char));

- danielpiedrahita January 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

type cast not required.

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

1. Syntax error
2. Returning int, should return char*
3. Not returning size

- mag January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It would be good to specify what exactly the syntax error is. The thing that's definitely an error is the comma between 10 and sizeof. Many compilers will also complain about the implicit cast of char* to int.

- eugene.yarovoi January 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Error would be too many arguments into the malloc function

- learner@89 January 24, 2015 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

char* error(){
	char* buf  = (char*)malloc(10*sizeof(char));
	return buf;

}

- m@}{ January 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Compilation Fails.. Mismatch return type.. However, if you got a customized compiler to ignore such cases.. than No issue.. malloc won't create any issue.. However the programmer has to put the memory check for really allocations has happened or not.... Two rectification req..

- hprem991 January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

OR

long error(){
	char* buf  = (char*)malloc(10*sizeof(char));
	return reinterpret_cast<long>(buf);

}

- m@}{ January 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

C doesn't have reinterpret_cast, and if it was C++, would have used new instead of malloc

- Dan June 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

error: too many arguments to function malloc
warning : return makes integer from pointer without cast

- Santosh Diwase March 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Error() Function returning an address.. is wrong....
The main function (calling function) will fail at runtime because buf goes out of scope , after error () function returns

- dss.chandra March 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Its valid to return a pointer from malloc(). You're thinking of the error of returning a pointer to a local automatic variable.

- Dan June 01, 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