4

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.

Comments
  • 3
    1000 a?
    An array with 1k index’s or something else??
  • 4
    If there are 6k variables id store them in a database to not clog up the memory
  • 0
    a, b ,c are the variables that are used in the program.
  • 0
    @BindView Yes, I agree with you. But these 6000 variables make the question more trickier. How will you declare this in C ??
  • 0
    @C0D4 No. Not using an array.
  • 0
    How will you declare 1000 a's , 2000 b's and 3000 c's in a program?@IllSlapU
  • 0
    It will not be an efficient or best solution for the problem.@C0D4
  • 0
    Okay I don’t know C or the answer to this. But I’m dying to know. Please gimme the answer!
  • 0
    It makes sense.@RantSomeWhere
  • 0
    This question belongs to that exclusion. :)@IllSlapU
  • 0
    surely I ll tell you the answer. Let some brains work first. :)@eshwarenm
  • 0
    Possible. But again its not the best solution@IllSlapU
  • 0
    Please tell me what is the best solution of storing 6k variables then
  • 0
    Struct and sizeof?

    Or a dictionary where the key is the hash of the struct?
  • 0
    int 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;
    }
    }
  • 0
    Pretty close. But still its not the best solution to the problem.@ard1998
  • 0
    The answer is :
    register int c,b,a
  • 0
    There 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.
  • 0
    This 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.
  • 3
    "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
  • 5
    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.
  • 0
    Please mention atleast 5 disadvantages. No offense. Just for knowledge purpose. @BindView
  • 3
    @pankaj33 no persistence, unreadable code, blocking, inefficient data storage, lack of scalability
  • 3
    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.
  • 3
    @pankaj33 @BindView Thanks! Exactly, this is so much of what is wrong with recruiting!
  • 2
    Okay now I can pretend I know C with my colleagues. Thanks!
  • 0
    LOL! :)@RantSomeWhere
  • 0
    It was asked exactly as I have written. Its written the same way as it was asked for the students. @daintycode
  • 0
    Even I thought I knew all of C. But this question shut me up. :)@eshwarenm
  • 1
    This is so called "Time Complexity". Space Complexity is never thought of.@daintycode
  • 0
    @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
  • 0
    @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
Add Comment