Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
pankaj331767y@BindView Yes, I agree with you. But these 6000 variables make the question more trickier. How will you declare this in C ??
-
Okay I don’t know C or the answer to this. But I’m dying to know. Please gimme the answer!
-
ard19981847yint counts[3] = {1000,2000,3000};
int? a[1000];
int? b[2000];
int? c[3000];
for(int i = 0; i<sizeof(counts)/4; i++){
for(int j=0; j<i; i++){
j[i]=null;
}
} -
pankaj331767yThere is a keyword in C named "register". Here you need to use register since the primary memory stores the data in registers. We declare "c" variable first, since its used most number of times. So in the beginning, the primary memory will store the "c" variables in the registers. But .... there is a twist in the tale. There are not so many registers that can hold 3000 c's. So during the execution, the old variables are loaded out of the registers and the new variables are stored into the registers.
-
pankaj331767yThis question was asked in one of the TCS interview. Out of 100 students , just one had written this amazing answer with an amazing explanation. And he was recruited by TCS.
-
"Register" is a keyword to indicate that its a heavily used variable and should be kept in cpu register. But what do i know im just a java guy
-
If tata hired someone based on that answer, that says a lot about the company. Also i can think of around 10 disadvantages of enterprise code being used like this.
-
pankaj331767yPlease mention atleast 5 disadvantages. No offense. Just for knowledge purpose. @BindView
-
@pankaj33 no persistence, unreadable code, blocking, inefficient data storage, lack of scalability
-
Please don't tell me that this question was asked exactly like you wrote it. There must've been at least a single little hint about shit has to be in registers or stuff like that.
Alone for the fact that arrays are in fact "better". In any way. Loading and unloading for simple value-keeping is an imense overhead. -
@pankaj33 @BindView Thanks! Exactly, this is so much of what is wrong with recruiting!
-
pankaj331767yIt was asked exactly as I have written. Its written the same way as it was asked for the students. @daintycode
-
pankaj331767yThis is so called "Time Complexity". Space Complexity is never thought of.@daintycode
-
@pankaj33 you telling me writing and reading from specific memory locations is slower than reading from somewhere (where is shit actually unloaded to and loaded from while we're at it?), writing it to the register and reading from there?^^
The worst case of this is (un)loading before every read, if i got this right?
I don't want to be cocky or something, i'm actually interested now.:D -
@pankaj33 i imagine this could be usable for predicted stuff, where the application learns what to allocate when based on usage BUT, how the fuck are 0.00004 ns faster access to a number make anything better (this speedup isn't even on the first access and even then you have at least some ticks for the comparsion and checking if shit is loaded)?
Yeah of course, "what about many accesses?" What, like 0.00004 times 10000? Still not really worth, especially when your "time complexity" is dominated by weird semaphores and multithreading in your whole system. I maybe get the idea, but don't see any real world use outside of mu-programming and not even there it makes much sense when using c (i guess).
When i'm wrong about this, tell me please, i'm genuinely curious about this shit now.:D
If there are 1000 a , 2000 b , 3000 c in a program, how will you declare them in C ??? Simple but high level aptitude question. Lets see who answers it right.
rant