I just failed a technical interview and they won't tell me the answers

Can you solve these questions? It's a big company in the news a lot and I didn't have to sign an NDA. If you tell me the answers I'll tell you the company.

Other urls found in this thread:

blogs.msdn.microsoft.com/tims/2010/10/29/pdc10-mysteries-of-windows-memory-management-revealed-part-two/
twitter.com/SFWRedditGifs

...

...

...

...

...

...

Offbyone
Corruption
Null ptr
Looks good

Toast me

...

Why the fuck are you copying the array just to print it out?
>2 * rgArray[i]
What the fuck is this? I don't see this an an answer?
I don't think I'd want to work for this company.

I'm not even going to read the rest.

posting new images takes too fucking long.

There's 10 total questions btw. This is the last one.

My answers were

question01: B
question02: F
question03: G
question04: B
question05: E
question06: G
question07: E
question08: G
question09: G
question10: B

Revel in my ignorance.

how the hell is stack memory corruption? I assumed it would be from heap memory. fuck.

malloc gives you heap memory
initialising something like this[1024]; places it on the stack
only space for 1024 characters is reserved, if the string was longer it would go past that and fuk shit up

Why are ALL these functions creating a temporary buffer for no reason?

>*(ptrMyArray+i)
why

Anyway OP, why don't you supply your answers?

Printing something is usually done as a substitute for actual work in a function. It's so the exercise doesn't complicate the code more than it should beside the goal.

I believe it's the

>double all values

Looks fine to me. nCount can overflow if it gets too high I guess.

>H) Yes, possible integer overflow
think outside of the box

>

I did

question01: B
question02: F
question03: G
question04: B
question05: E
question06: G
question07: E
question08: G
question09: G
question10: B

Were there any whiteboards in the interview, user?

This is C++: dynamically sized arrays are declared with "new" and allocated in the heap.

Off by one error. This can assign a 0 outside the range specified.

>int* ptrMyArray = new int[nSize];
This would not compile.

Don't bring this up ever again.

I'm glad I only program as a hobby. I don't know if my code works until I run it. I would definitely fail if someone asked me to look at code and point out any errors.

b: i

Why not?

F, nCount isn't initialized to 0, but maybe I'm dumb and C++ sets variables to 0 by default?

>C++ sets variables to 0 by default?
It most definitely doesn't.

It does in a new process. By default Windows and Unix will zero out a new address space for you. So you can safely assume the very first initializarion is 0, however any subsequent calls init'ing local vars may not have 0's.

>unsafe langauge
That is where these examples are wrong.

No, fuck you or post the source of your ridiculous claims. It doesn't work like that and it never has.

If malloc fails there could go stuff wrong right?

possible off by one

>C but with classes

OP here the company in question is Hot Topic in Phoenix AZ. I'm trying to impress this girl working there by answering these questions for her.

possible memory leak. If fopen("out.jpg" returns null, the function returns -1 before freeing memory

so this isnt for you?
>also pic of grill?

The major error all of these have in common is that the fellow programmer expects you to clean up after his shit. Do your own fucking work, scrub. I have stuff to do too, you know? We have deadlines. Stop bugging me with trivial shit. Why are you in my office anyway? HAVE YOU EVEN TRIED COMPILING? READ THE FUCKING ERROR MESSAGES

For the first one, it is C) because *(ptrMyArray+i) causes memory leak on ints in ur array why are u using +i bruh

nvm im retard

it's called pointer arithmetic

*(ptrMyArray+i) and ptrMyArray[i] have the exact same meaning

so does i[ptrMyArray]
:^)

Don't see anything wrong, I might be dumb though

What happens if user gives negative nSize here, do possibilities like these count, I don't even

Also
>all of questions
>assuming your coworkers gender
>he or she
>not using the all the pronouns like zhe
>not knowing there are 56 genders
Trust me op you don't want to work for this bigoted company

no that just means you're retarded

The real answer is to stop doing all this unsafe array[N]/raw pointer shit and give that retard a C++ book from this century.

for loops should be nSize-1
doesn't check if pointer resolves to anything before starting
doesn't check if nSize is positive
I think it's ok but am example of retardation
should be nSize-1
this looks ok, assuming delete [] is a real thing c++ can do
depends if you assume nSize is always accurate. If so off by one, if not memory corruption and infinite loop as well
works but really should be a for loop
I see nothing wrong and it's even readable
I don't know c++

t. jspfag who hasn't touched c/c++ in 10 years

*(int* + int) = *(int*) = int
int*[int] = int
int[int*] is not valid

My C autism is tingling.

This one is actually null pointer dereference, since the return value of malloc isn't checked, and malloc will return null if the allocation failed.

Now that's an infinite loop, desu.

>doesn't check if nSize is positive
No. The code is correct. The documentation made it clearly that nSize must be positive. nSize == 0 could be discussed.

Thanks for answering everyone. The company is Space x.

Was this some online assignment or what?

No. I failed that test yesterday. I don't expect to get hired by them later so meh. I need to get better for my other upcoming interviews which is why I need to know how I screwed up on this one.

The worst part is that this is the first barrier to entry before I could do a phone interview. I'm not even good enough to pass it.

> fuck you or post the source of your ridiculous claims
Linux kernel does the same. Now learn the basics of OS design kay.

blogs.msdn.microsoft.com/tims/2010/10/29/pdc10-mysteries-of-windows-memory-management-revealed-part-two/
> As a process demands memory, it is faulted in from the zero page list [..] Firstly, the zero page thread runs at the lowest priority and is responsible for zeroing out free pages before moving them to the zeroed page list

Are you fucking kidding me? was it for QA or some other bullshit position, or actually SDE? those questions were too simple

Fucking shit, you would expect they were using SPARK, not codemonkey C++.... I mean, COME ON, it's fucking 2017!

You don't seem to understand that practical languages with lots of users trump special snowflake stuff any day of the week for production purposes. C++ is fast, a lot of people know it and there's lots of very well tested libraries that go along with it.

Also, I said two post above yours that this was the barrier for entry, this is before someone even gets phone screened.

In addition, I only had 45 minutes to solve them all.

Congrats, you're clinically retarded.

None of them would have any error messages or compilation issues. Most would even work in most, if not all realistic, scenarios (but fail in edge cases anyway). You're literally more incompetent than OP, who is objectively retarded.

Good thing you failed then desu.
You don't want to work for a charlatan (Musk) who severely underpays his workforce because he deludes them into thinking they are progressing humanity.
Honestly working for Amazon sounds more bearable from what I've heard. Fucking Amazon.

Ignore the other guys I'm 99% sure this is fine

Thanks for letting me know that I suck. I will try to improve.

Do you niggers even C?

#include

int main(int argc, char **argv)
{
int a[] = {1, 2};
printf("%d == %d\n", a[1], 1[a]);
return 0;
}


Explain this.

while (bKeepGoing = true) will set keepgoing to true instead of comparing and loop forever

if you don't have enough memory malloc will return null and you'll have a null pointer dereference, but other than that it looks fine

Is there exercises like this elsewhere? Like on a book or something?

>has asked you to look over a function
yes, that's not a function

Okay, so what is the company, then?

people writing C++ needs to learn unit testing is what I see when I read code like this

>Are you fucking kidding me? was it for QA or some other bullshit position, or actually SDE? those questions were too simple

You know that blog post about how most college graduates and software developers can't do fizzbuzz? It isn't a joke.

Actually it is use of uninitialized local variable, he checks for null pointer dereference. nCount can be anything so it won't return the number of times a number greater than nThreshold is present, it will return random values + number of times a number greater than nThreshold is present.

but if nSize is negative, its a possible infinite loop

other questions check if nSize is negative and do nothing or return a error

I'm beyond fizz buzz capabilities but some of these still stumped me. I seriously think you underestimate how much working in an environment that exposes you to these edge cases helps. Everyone if I've done tons of leet code it's still left a gap.

I'm not too sure how to fix it aside tbqh.

D.) Forgot to check if ptrHaystack is a null pointer

What is this meme?

stupid frog poster

is this wrong because ptrString could be more than 1024 characters long, and so the for loop would smash the stack? ie memory corruption?

OP thanks for posting these. making me brush up on my C

easy off by one:

Here OP, I did your homework

B

C

F

D, but in the real world you'd just let it crash, since if you're OOM you're fucked anyway, it's a personal G from me

B

nSize has to be positive, I'd say they want you to answer E, but really, in the real world it'd be a size_t and a <


---

I'm stopping here, this is too retarded

>Looks good
Nope.
Return value of malloc is not checked. It's a null pointer dereference.

You're a fucking idiot.

This code is erroneous but none of the options fit it.
He's not checking that nSize is larger than 0.

>its a possible infinite loop
Wrong. It'll wrap around at some point and terminate.

My best reading is
Q1
> Memory corruption, you can't trust user input to be properly terminated
Q2
> Uninitialized variable nCount
Q3
> Good, but others pointed out malloc fail
Q4
> Off by one
Q5
> Proper, I wouldn't say negative size is enough to count it wrong
Q6
> Memory leak on failed open
Q7
> '=' instead of '==', infinite loop
Q8
> Null pointer dereference
Q9
> Glorious proper C
Q10
> Off by one, '

+1

Sorry Sir but I code only Javascript.

Am I horribly miss-remembering C or wouldn't *(ptrMyArray+i) create problems there since new integer begins every 4 bytes, so it should be ptrMyArray + (i * sizeofint) instead?

I found this one actually to be a harder one since it's so easily overlooked. And if you start seeing the possibility that some languages start from 1 (like lua) it might be easily ignored.

Once it throws an error though it's easy to spot whats wrong.

>hit compile button
>get a list of errors
ez

>babby's first deployment

Wtf, I can only guess it replaces the expression by *(ptr + x) so *(x + ptr) would be the same.

It prob should not compile though since it's fucking weird.

> Am I horribly miss-remembering C
This.

Is there anything more awful than the "find the error in someone elses code"?