Some Questions Asked in Interview

Discussion in 'C Programming' started by Jatinder, May 14, 2004.

  1. Jatinder

    Jatinder Guest

    I 'm a professional looking for the job.In interview these questions
    were asked with some others which I answered.But some of them left
    unanswered.Plz help.

    Here are some questions on C/C++, OS internals?
    Q1 . What is the use of pointer to an array?
    Q2 . What is the use of array of pointers?
    Q3 . What is the use of pointer to function ?
    Q4 . How to print through serial port? What is Flow Control(Xon,Xoff)
    ?
    Q5 . What is IOCTL Explain .
    Q6 . How to create an interrupt service routine in C?
    Q7 . What are the internals of a schedular ?
    Q8 . The static variables are declared in heap or stack ?
     
    Jatinder, May 14, 2004
    #1
    1. Advertisements

  2. These are not all C questions, and can also have quite lengthy answers.
    I won't give any answer becuase I feel the C questions are too vague.
    Details on IOCTL can be found on the web, as can information about XON,
    XOFF.
     
    Spacen Jasset, May 14, 2004
    #2
    1. Advertisements

  3. Useful to for anonymous reverse invocation. Most useful to invoke
    application's function from library.
    man ioctl. You will get nice explantion
    We can write only software interrupts and they are called signal
    handlers. These are like normal c functions those take an integer (sig
    num) as argument
    not a c question. It requires vague explanation
    heap
     
    Dhananjaya Reddy Eadala, May 14, 2004
    #3
  4. Jatinder

    Lew Pitcher Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1
    Actually, this is not a C question. IOCTLs are outside the scope of the
    standard C language. /And/ the unix 'man' command isn't necessarily
    available to the OP.

    [snip]
    Perhaps not. The standard C language neither recognizes the term 'heap',
    nor the term 'stack', and thus the question doesn't actually relate to
    C. As for specific implementations, both 'heap' and 'stack' are eligible
    to store static variables, although IMHO 'stack' would take more work to
    implement.




    - --

    Lew Pitcher, IT Consultant, Enterprise Application Architecture
    Enterprise Technology Solutions, TD Bank Financial Group

    (Opinions expressed here are my own, not my employer's)
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (MingW32)

    iD8DBQFApOLIagVFX4UWr64RAmmEAJ9RadHvs/U6vO+FZ5UGeptgAaedjACeP7Dg
    uVMv7O4+6DMhR0ucYdz8Ecg=
    =xRlU
    -----END PGP SIGNATURE-----
     
    Lew Pitcher, May 14, 2004
    #4
  5. Jatinder

    Xenos Guest

    I find it alarming that this trend of giving ridiculous quizzes and tests to
    interviewee is increasing. When I was young and looking for a job,
    companies that did this were few. I immediately walked out of any interview
    were I was asked to take such a test. Regurgitation of facts does not prove
    knowledge or wisdom, and is certainly no indication of skill. For someone
    with an encyclopedic memory of the C or C++ standards, I would hire for a
    one-time fee of $18--the amount I would need to just purchase a copy of the
    standard (or whatever it currently costs).

    This topic has come up before, and I think I said pretty much the something.
    Someone replied with, "So how do you know they can do the job?" Well, there
    are no guarantees, but you could try *talking* to them. I never minded
    being asked questions in interviews. Isn't that a major part of the
    process? Ask about college courses taken and projects done. If you are
    interviewing an experienced professional, ask about previous work done. How
    about what problems were encountered and how they were overcome. DON'T try
    and sitting me in a room with 50 other nameless applicants and presume to
    give me a test. That's a company interested in bodies and tests scores, not
    cultivating good people. I'm also turned off by companies that call you up
    and ask for college transcripts. Unless they have taken the time to
    interview me and show an interest in hiring me, I always refused.

    As a result, I love the company I work for. They treat me very well, and
    there is always very smart, experienced people to learn from.

    DrX
     
    Xenos, May 14, 2004
    #5
  6. Jatinder

    Ben Pfaff Guest

    Such things are rarely useful. It is far more common to point to
    the first element of an array.
    This question is so general that it is absurd. You can use
    arrays of pointers for any number of things. For example, you
    can store pointers to elements to be sorted within the array, and
    then sorting will just require moving pointers instead of the
    (presumably larger) elements themselves.
    Q4 through Q7 are off-topic for comp.lang.c
    No.
     
    Ben Pfaff, May 14, 2004
    #6
  7. Jatinder

    Malcolm Guest

    To pass the array to a function.
    To pass a list of arrays to a fucntion.
    To pass a function to a function.
    Not a clue. Ports vary from platform to platform.
    An acronym. Not a clue what it means.
    You can't do this in standard C. Refer to your compiler documentation.
    Huh? A clock and a series of function pointers it calls at appropriate
    times, I would guess.
    Neither. They are usually in their own area of memory which is allocated at
    program initialisation.
     
    Malcolm, May 14, 2004
    #7
  8. Jatinder

    Guillaume Guest

    I find it alarming that this trend of giving ridiculous quizzes and tests to
    Well, as for me, I don't particularly find it alarming that technical
    questions be asked during job interviews - even if it looks like a
    formal "test".
    After all, education itself is not enough to judge someone's
    skills. And related past work may be just lies or edulcorated stories -
    unless the human resources staff checks them thoroughly, which is not
    always possible nor practical.

    What I find alarming in the above questions is that at least half of
    them don't make any sense or are so general that they can't be answered
    directly. I find alarming that it seems these questions have been
    written by someone inept in the technical and software engineering
    fields, and may disqualify skilled people and qualify people who can't
    write actual software.
     
    Guillaume, May 14, 2004
    #8
  9. Little. Usually you don't point to arrays.


    Some. You may need to point to more than one thing at a time.


    Immense. You can't call a function without pointing to it.


    Stick a pen through it. If you make a mess you need to control the ink flow.


    Sorry, I've seen some IOCTLs but never that one.


    An infinite loop often does the trick.


    The concept of an event is quite general. They aren't likely to have
    common internals.


    False. They are typically declared near the beginning of the
    program unless they are local to some function.
     
    Jarno A Wuolijoki, May 15, 2004
    #9
  10. Jatinder

    Mabden Guest

    TO step through the array, or pass it by reference to another function.

    A list of strings of various sizes, or it could be an array of function
    pointers. If one has 20 field validation functions (check_ssn, check_phone,
    check_zip, etc.) you could put them in an array of pointers and attach the
    pointer to a field on a form.

    See above, you can put them in an array and call them like this: validate
    (field, vals[check_zip]);

    That's what parallel ports are for. Who cares. I use USB.

    A dinosaur. DOS based device-driver accessor: ioctl (handle, cmd, &dx, &cx);
    Time to upgrade.

    signal ();
    With this you can capture Ctrl-C, divide by zero, etc.

    A state machine?

    Undefined, but the answer desired is probably heap.
     
    Mabden, May 15, 2004
    #10
  11. Jatinder

    pete Guest

    A pointer to an array is also handy for mallocating
    a multidimensional array, using only one pointer.
     
    pete, May 15, 2004
    #11
  12. You can't step through an array using a pointer to it.
    If you increment a pointer to an array by 1 you will point
    one past the end of the object (the array in this case) this
    is defined, but you cannot dereference this pointer as that
    leads to undefined behaviour.

    A pointer to an array is rarely useful, I have never had the
    need for one.
     
    Thomas stegen, May 15, 2004
    #12
  13. Jatinder

    Mabden Guest

    You are assuming I am incompetent. I would either keep a count on members or
    add a terminating value to the array. Running off the end, or "off by one"
    is a common error that one must plan to handle. Please don't tell me I can't
    do something because you see a trivial restriction. When you say "you can't"
    I think of going to the moon. You would have said the same thing back then,
    "you can't"

    I can.
     
    Mabden, May 16, 2004
    #13
  14. I guess you're overlooking the difference between "pointer to an array"
    and "pointer to the first element of an array". The OP probably meant the
    second but when you take it to mean what it really says a pointer to an
    array would be something like

    int array[ 10 ];
    int ( * pointer_to_array_of_ten_ints )[ 10 ] = &array;

    And that construct probably would tend to be used not that often;-)

    Regrds, Jens
     
    Jens.Toerring, May 16, 2004
    #14
  15. Jatinder

    James Kanze Guest

    |> >> Q8 . The static variables are declared in heap or stack ?

    |> > heap

    |> Perhaps not. The standard C language neither recognizes the term
    |> 'heap', nor the term 'stack', and thus the question doesn't actually
    |> relate to C. As for specific implementations, both 'heap' and
    |> 'stack' are eligible to store static variables, although IMHO
    |> 'stack' would take more work to implement.

    On the systems I'm familiar with, the answer would be neither.
     
    James Kanze, May 16, 2004
    #15
  16. Jatinder

    James Kanze Guest

    |> |> > I 'm a professional looking for the job.In interview these
    |> > questions were asked with some others which I answered.But some of
    |> > them left unanswered.Plz help.

    |> > Here are some questions on C/C++, OS internals?
    |> > Q1 . What is the use of pointer to an array?
    |> > Q2 . What is the use of array of pointers?
    |> > Q3 . What is the use of pointer to function ?
    |> > Q4 . How to print through serial port? What is Flow Control(Xon,Xoff)
    |> > ?
    |> > Q5 . What is IOCTL Explain .
    |> > Q6 . How to create an interrupt service routine in C?
    |> > Q7 . What are the internals of a schedular ?
    |> > Q8 . The static variables are declared in heap or stack ?

    |> I find it alarming that this trend of giving ridiculous quizzes and
    |> tests to interviewee is increasing.

    It depends. The above questions aren't multiple choice, and can lead to
    interesting and thoughtful answers. At least, some could.

    In my experience, such "quizzes" are most useful if given orally and
    interactively by someone familiar with the topic. Less formally, I
    suspect that most people called on to vet a number of so-called
    specialists will make up a list of questions to start with. After the
    first few, of course, you play it by ear, adjusting to the apparent
    competence of the person being interviewed.
     
    James Kanze, May 16, 2004
    #16
  17. Jatinder

    James Kanze Guest

    |> Mabden wrote:

    |> >>Q1 . What is the use of pointer to an array?
    |> > TO step through the array, or pass it by reference to another
    |> > function.

    |> You can't step through an array using a pointer to it. If you
    |> increment a pointer to an array by 1 you will point one past the end
    |> of the object (the array in this case) this is defined, but you
    |> cannot dereference this pointer as that leads to undefined
    |> behaviour.

    |> A pointer to an array is rarely useful, I have never had the need
    |> for one.

    Nonsense. If a is a two dimensional array, the expression a returns
    a pointer to an array.
     
    James Kanze, May 16, 2004
    #17


  18. No it doesn't. It returns an array, which "decays" into a pointer when
    used as a value. a itself "decays" into a pointer to an array when used
    as a value. "Decays" does not mean "is", as Chris Torek will explain at
    length given half the chance.
     
    Joona I Palaste, May 16, 2004
    #18


  19. Well, lets look at that. As you probably know very well there aren't
    any true multidimensional arrays in C, they are basically syntactic
    sugar, made up from flat, one-dimensional arrays. And the rules for
    such arrays, like for example

    int a[ N ][ M ];

    are to evaluate

    a[ i ][ j ] := *( a + i * M + j )

    and

    a[ i ] := a + i * M

    where 'a' itself is a pointer to the first element of that "two-dimen-
    sional" array (not a "pointer to a two-dimensional array"). So the type
    of 'a' isn't "pointer to array" but (in this case) "pointer to int".

    It seems to be a common misconception that with

    int b[ 20 ];

    'b' would be of type "pointer to array". But 'b' is of type "pointer to
    int", pointing to the first element of the array, so you loosely can
    call it an "array pointer". But only '&b' is of type "pointer to array
    (of 20 ints)". You will see that easily when you create type of "pointer
    to array (of 20 ints)" e.g. using a typedef to make things easier to
    read (and not to offend Emmanuel sense of beauty;-):

    typedef int ( *AP )[ 20 ];

    AP a;

    If you now try

    int b[ M ];

    a = b;

    you will get a "assignment from incompatible pointer type" error, and
    you must change that to

    a = &b;

    to get it working.
    Regards, Jens
     
    Jens.Toerring, May 16, 2004
    #19
  20. Jatinder

    James Kanze Guest

    -berlin.de writes:


    |> > |> Mabden wrote:

    |> > |> >>Q1 . What is the use of pointer to an array?
    |> > |> > TO step through the array, or pass it by reference to
    |> > |> > another function.

    |> > |> You can't step through an array using a pointer to it. If you
    |> > |> increment a pointer to an array by 1 you will point one past
    |> > |> the end of the object (the array in this case) this is
    |> > |> defined, but you cannot dereference this pointer as that leads
    |> > |> to undefined behaviour.

    |> > |> A pointer to an array is rarely useful, I have never had the
    |> > |> need for one.

    |> > Nonsense. If a is a two dimensional array, the expression a
    |> > returns a pointer to an array.

    |> Well, lets look at that. As you probably know very well there aren't
    |> any true multidimensional arrays in C, they are basically syntactic
    |> sugar, made up from flat, one-dimensional arrays.

    Right.

    I think you'll agree that if a is declared as a 2 diminsional array, the
    expression a + i is a pointer to an array. I think I got carried away
    with a -- a is an array, which decays to a pointer to the first
    element in certain cases.

    |> And the rules for such arrays, like for example

    |> int a[ N ][ M ];
    |>
    |> are to evaluate

    |> a[ i ][ j ] := *( a + i * M + j )

    Not quite. It evaluates to *(a + i) + j. In this case, a decays to a
    pointer to an array (the first element of a, and int[M]); i is added to
    this pointer, which gives a pointer to an array, the i'th array in a.
    This pointer then decays to a pointer to the first element, to which j
    is added.

    The expression you wrote will typically invoke undefined behavior
    (except for special cases, e.g. where i and j equal 0).

    |> and

    |> a[ i ] := a + i * M

    No. The expression a is explicitly defined by the standard as *(a+i).

    You never, never multiply by M. Behind the scenes, of course, the
    compiler will multiply by sizeof(a), i.e. the size of an int[M]. But
    that is simply the implementation technique, and is no different than
    when you have an array of struct's or whatever.

    |> where 'a' itself is a pointer to the first element of that
    |> "two-dimensional" array (not a "pointer to a two-dimensional
    |> array").

    Not quite. Read your first sentence: there are no two-dimensional
    arrays, just arrays of arrays. So a decays to a pointer to the first
    element of a, and the type of that element is an int[M].

    |> So the type of 'a' isn't "pointer to array" but (in this case)
    |> "pointer to int".

    No, the type of a is int[M]. Not pointer to array, since we've
    already dereferenced the pointer. But array of int.

    Depending on what you do next, that array may decay into a pointer. Or
    may not: what does sizeof( a ) return?

    |> It seems to be a common misconception that with

    |> int b[ 20 ];

    |> 'b' would be of type "pointer to array".

    Not with anyone who has every used C. The common misconception seems to
    be that b is a pointer to int, and that the declarations:
    extern int * b ;
    and
    extern int b[] ;
    are equivalent, and can be used interchangeably.

    |> But 'b' is of type "pointer to int", pointing to the first element
    |> of the array, so you loosely can call it an "array pointer".

    No, that is the common misconception. b is of type array[20] of int.

    |> But only '&b' is of type "pointer to array (of 20 ints)". You will
    |> see that easily when you create type of "pointer to array (of 20
    |> ints)" e.g. using a typedef to make things easier to read (and not
    |> to offend Emmanuel sense of beauty;-):

    |> typedef int ( *AP )[ 20 ];

    |> AP a;

    |> If you now try

    |> int b[ M ];

    |> a = b;

    |> you will get a "assignment from incompatible pointer type" error, and
    |> you must change that to

    |> a = &b;

    |> to get it working.

    But I was talking about 2 dimentional arrays. And
    int b[ 10 ][ 20 ] ;
    AP a = b ;
    should work.

    Although my example went a step too far -- I should have said a+i,
    rather than a (which is, of course *(a+i)). But the point remains;
    you cannot use two dimensional arrays in C without using pointers to
    arrays. Even if typically, you don't write them explicitly.

    Another obvious case, of course: what is the type of the parameter of:
    int f( int a[5][5] ) ;
     
    James Kanze, May 16, 2004
    #20
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.