Your opinion

Discussion in 'C Programming' started by Ravi, Sep 22, 2003.

  1. Ravi

    Ravi Guest

    #define A B
    #define B A

    main()
    {
    int A=5;
    float B=6.0;
    printf("\n %d %f",A,B);
    printf(" %d %f",B,A);
    }

    Take a look at this program. What is the output?
    Is it implementation dependent?

    Do you think this question aim's at analising a person's C skills?
    (It was asked in a Technical skill paper)

    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    Ravi, Sep 22, 2003
    #1
    1. Advertising

  2. Ravi

    Ben Pfaff Guest

    Ravi <> writes:

    > #define A B
    > #define B A


    Pointless and stupid and effectively a no-op besides.

    > main()


    You should declare main() as explicitly returning `int'. This is
    required in C99. You should also write `void' within the
    parentheses to give it a prototype, though it is not required.

    > {
    > int A=5;
    > float B=6.0;
    > printf("\n %d %f",A,B);
    > printf(" %d %f",B,A);


    You should return a value from main().

    > }
    >
    > Take a look at this program. What is the output?
    > Is it implementation dependent?


    It is undefined for at least two reasons: first, trying to print
    out an `int' using %f; second, for failing to write a final
    new-line character to stdout.

    > Do you think this question aim's at analising a person's C skills?
    > (It was asked in a Technical skill paper)


    I think it aims at testing something, but it has little to do
    with C skills, especially considering the stupid macro
    definitions. It tests knowledge of C trivia, not knowledge of C
    usage.
    --
    Just another C hacker.
     
    Ben Pfaff, Sep 22, 2003
    #2
    1. Advertising

  3. Ravi

    Nick Austin Guest

    On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:

    >#define A B
    >#define B A
    >
    >main()
    >{
    > int A=5;
    > float B=6.0;
    > printf("\n %d %f",A,B);


    Undefined behavior.

    > printf(" %d %f",B,A);


    Undefined behavior thrice.

    >}


    Nick.
     
    Nick Austin, Sep 22, 2003
    #3
  4. Ravi

    Ben Pfaff Guest

    Nick Austin <> writes:

    > On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >
    > >#define A B
    > >#define B A
    > >
    > >main()
    > >{
    > > int A=5;
    > > float B=6.0;
    > > printf("\n %d %f",A,B);

    >
    > Undefined behavior.


    In that line? Where?
    --
    "I should killfile you where you stand, worthless human." --Kaz
     
    Ben Pfaff, Sep 22, 2003
    #4
  5. Ravi

    Ravi Guest

    On 22 Sep 2003 09:44:56 -0700, Ben Pfaff <> wrote:

    >> main()

    >
    >You should declare main() as explicitly returning `int'. This is
    >required in C99. You should also write `void' within the
    >parentheses to give it a prototype, though it is not required.


    What's worse it had void main() originally and also a clrscr()
    somewhere in between.

    And the funniest part:
    "What is the output on compiling the program:"
    When they actually meant running the program.

    LOL
    And they think they are testing someones technical skill.

    One more redicilous question:
    #define scanf "%s is a string"
    void main()
    {
    printf(scanf,scanf);
    }

    What's the output?
    I think the output of this is not certain as well.

    (Don't blame me as THEY did not feel like including any header file
    and felt like using void main()
    )
     
    Ravi, Sep 22, 2003
    #5
  6. Ben Pfaff wrote:
    > Nick Austin <> writes:
    >
    >
    >>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >>
    >>
    >>>#define A B
    >>>#define B A
    >>>
    >>>main()
    >>>{
    >>> int A=5;
    >>> float B=6.0;
    >>> printf("\n %d %f",A,B);

    >>
    >>Undefined behavior.

    >
    >
    > In that line? Where?


    I'd bet on "using a variadic function without a prototype in scope"...

    --
    Bertrand Mollinier Toublet
    "No sea vivo, Buendia" -- El presidente del tribunal,
    in Cien anos de soledad, de Gabriel Garcia Marquez
     
    Bertrand Mollinier Toublet, Sep 22, 2003
    #6
  7. Ben Pfaff <> wrote:

    >Nick Austin <> writes:
    >
    >> On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >>
    >> >#define A B
    >> >#define B A
    >> >
    >> >main()
    >> >{
    >> > int A=5;
    >> > float B=6.0;
    >> > printf("\n %d %f",A,B);

    >>
    >> Undefined behavior.

    >
    >In that line? Where?


    No prototype for printf() in scope, hence UB.

    Regards

    Irrwahn
    --
    My other computer is a abacus.
     
    Irrwahn Grausewitz, Sep 22, 2003
    #7
  8. Ravi

    Ravi Guest

    On Mon, 22 Sep 2003 18:16:45 +0100, Nick Austin
    <> wrote:

    >On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >
    >>#define A B
    >>#define B A
    >>
    >>main()
    >>{
    >> int A=5;
    >> float B=6.0;
    >> printf("\n %d %f",A,B);

    >
    >Undefined behavior.
    >
    >> printf(" %d %f",B,A);

    >
    >Undefined behavior thrice.
    >
    >>}

    >


    Ok, I get the point. But if you were asked this question in a
    technical test with 4 options

    a) error during compilation
    b) goes into an infinite loop
    c) 5 6.000000 6 5.000000
    d) 5 6.000000 0 0.000000

    What would you choose?
     
    Ravi, Sep 22, 2003
    #8
  9. Ravi <> wrote:

    >On Mon, 22 Sep 2003 18:16:45 +0100, Nick Austin
    ><> wrote:
    >
    >>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >>
    >>>#define A B
    >>>#define B A
    >>>
    >>>main()
    >>>{
    >>> int A=5;
    >>> float B=6.0;
    >>> printf("\n %d %f",A,B);

    >>
    >>Undefined behavior.
    >>
    >>> printf(" %d %f",B,A);

    >>
    >>Undefined behavior thrice.
    >>
    >>>}

    >>

    >
    >Ok, I get the point. But if you were asked this question in a
    >technical test with 4 options
    >
    >a) error during compilation
    >b) goes into an infinite loop
    >c) 5 6.000000 6 5.000000
    >d) 5 6.000000 0 0.000000
    >
    >What would you choose?


    e) I do not want to work for this company, bye.

    ;-)

    Irrwahn
    --
    My other computer is a abacus.
     
    Irrwahn Grausewitz, Sep 22, 2003
    #9
  10. Ravi

    Mark Gordon Guest

    On Tue, 23 Sep 2003 00:12:57 +0530
    Ravi <> wrote:

    > On Mon, 22 Sep 2003 18:16:45 +0100, Nick Austin
    > <> wrote:
    >
    > >On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    > >
    > >>#define A B
    > >>#define B A
    > >>
    > >>main()
    > >>{
    > >> int A=5;
    > >> float B=6.0;
    > >> printf("\n %d %f",A,B);

    > >
    > >Undefined behavior.
    > >
    > >> printf(" %d %f",B,A);

    > >
    > >Undefined behavior thrice.
    > >
    > >>}

    > >

    >
    > Ok, I get the point. But if you were asked this question in a
    > technical test with 4 options
    >
    > a) error during compilation
    > b) goes into an infinite loop
    > c) 5 6.000000 6 5.000000
    > d) 5 6.000000 0 0.000000
    >
    > What would you choose?


    Depends on whether I wanted the job. They probably expected d, but I
    would definitely be inclined to point out that the question was absurd
    and that the code invoked UB. However I don't think I would want a job
    where they asked such questions.
    --
    Mark Gordon
    Paid to be a Geek & a Senior Software Developer
    Although my email address says spamtrap, it is real and I read it.
     
    Mark Gordon, Sep 22, 2003
    #10
  11. Ravi wrote:

    > #define A B
    > #define B A
    >
    > main()
    > {
    > int A=5;
    > float B=6.0;
    > printf("\n %d %f",A,B);
    > printf(" %d %f",B,A);
    > }
    >
    > Take a look at this program. What is the output?


    The same as if the #defines were not there.

    > Is it implementation dependent?


    The possibility that it might successfully compile and run is
    implementation dependent.
    >
    > Do you think this question aim's at analising a person's C skills?


    Only if the correct answer included noticing
    1) failure to #include <stdio.h>, to provide the needed prototype for the
    variadic function printf.
    2) failure to specify the corrent return type of main(), required by C99.
    3) failure to return a value from a function which (in C89/C90) promised
    implicitly to return an int.
    4) mismatched printf specifiers and arguments, attempting stupidly to
    print a float with the int specifier %d and to print an int with the
    double specifier %f.
    5) failure to terminate the last output line with a line-termination
    character ('\n'), resulting in implementation-defined behavior.
    6) stupid (and pointless) preprocessor tricks.

    > (It was asked in a Technical skill paper)


    And did the answer include the above points?



    --
    Martin Ambuhl
     
    Martin Ambuhl, Sep 22, 2003
    #11
  12. Nick Austin wrote:

    > On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >
    >
    >>#define A B
    >>#define B A
    >>
    >>main()
    >>{
    >> int A=5;
    >> float B=6.0;
    >> printf("\n %d %f",A,B);

    >
    >
    > Undefined behavior.


    Balony. Printing an int with %d and a float with %f is just fine.




    --
    Martin Ambuhl
     
    Martin Ambuhl, Sep 22, 2003
    #12
  13. Ravi wrote:

    > #define A B
    > #define B A
    >
    > main()
    > {
    > int A=5;
    > float B=6.0;
    > printf("\n %d %f",A,B);
    > printf(" %d %f",B,A);
    > }
    >
    > Take a look at this program. What is the output?
    > Is it implementation dependent?
    >
    > Do you think this question aim's at analising a person's C skills?
    > (It was asked in a Technical skill paper)
    >



    Thank you for this post, Ravi.

    Output: 5 6.000000 0 0.000000
    (There is one space before the 5.)

    I don't know if it's implementation dependent.

    The code that you cite from the technical skill paper is referred to
    as "spaghetti code" by _The New Hacker's Dictionary_. Spaghetti code
    is code with an unnecessarily complex and tangled control structure.

    http://www.jargon.8hz.com/jargon_34.html#SEC41

    _The New Hacker's Dictionary_ is by Eric S. Raymond.


    --Steve
     
    Steve Zimmerman, Sep 22, 2003
    #13
  14. Ravi

    Nick Austin Guest

    On Tue, 23 Sep 2003 00:12:57 +0530, Ravi <> wrote:

    >>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >>
    >>>#define A B
    >>>#define B A
    >>>
    >>>main()
    >>>{
    >>> int A=5;
    >>> float B=6.0;
    >>> printf("\n %d %f",A,B);
    >>> printf(" %d %f",B,A);
    >>>}

    >>

    >
    >Ok, I get the point. But if you were asked this question in a
    >technical test with 4 options
    >
    >a) error during compilation
    >b) goes into an infinite loop
    >c) 5 6.000000 6 5.000000
    >d) 5 6.000000 0 0.000000
    >
    >What would you choose?


    a) is a serious contender, but the examiner probably expects d).

    The question is obviously flawed for not including:

    e) outputs only a single newline.

    Nick.
     
    Nick Austin, Sep 22, 2003
    #14
  15. Ravi

    Ravi Guest

    On Mon, 22 Sep 2003 21:29:32 +0200, Irrwahn Grausewitz
    <> wrote:

    >Ravi <> wrote:
    >
    >>On Mon, 22 Sep 2003 18:16:45 +0100, Nick Austin
    >><> wrote:
    >>
    >>>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >>>
    >>>>#define A B
    >>>>#define B A
    >>>>
    >>>>main()
    >>>>{
    >>>> int A=5;
    >>>> float B=6.0;
    >>>> printf("\n %d %f",A,B);
    >>>
    >>>Undefined behavior.
    >>>
    >>>> printf(" %d %f",B,A);
    >>>
    >>>Undefined behavior thrice.
    >>>
    >>>>}
    >>>

    >>
    >>Ok, I get the point. But if you were asked this question in a
    >>technical test with 4 options
    >>
    >>a) error during compilation
    >>b) goes into an infinite loop
    >>c) 5 6.000000 6 5.000000
    >>d) 5 6.000000 0 0.000000
    >>
    >>What would you choose?

    >
    >e) I do not want to work for this company, bye.


    But I want to.
    Great pay for a fresher like me!
     
    Ravi, Sep 22, 2003
    #15
  16. On Mon, 22 Sep 2003, Steve Zimmerman wrote:
    >
    > Ravi wrote:
    > > #define A B
    > > #define B A
    > >
    > > main()
    > > {
    > > int A=5;
    > > float B=6.0;
    > > printf("\n %d %f",A,B);
    > > printf(" %d %f",B,A);
    > > }
    > >
    > > Take a look at this program. What is the output?
    > > Is it implementation dependent?
    > >
    > > Do you think this question aim's at analising a person's C skills?
    > > (It was asked in a Technical skill paper)

    >
    >
    > Thank you for this post, Ravi.
    >
    > Output: 5 6.000000 0 0.000000
    > (There is one space before the 5.)
    >
    > I don't know if it's implementation dependent.



    STOP STOP STOP STOP STOP STOP STOP STOP STOP!

    Thank you.


    > The code that you cite from the technical skill paper is referred to
    > as "spaghetti code" by _The New Hacker's Dictionary_. Spaghetti code
    > is code with an unnecessarily complex and tangled control structure.


    Two variables and linear control flow is *not* spaghetti code,
    no matter how little you understand of it. "Spaghetti code"
    refers to code with complex and/or hard-to-follow control
    flow, such as would be difficult to trace on paper.

    -Arthur
     
    Arthur J. O'Dwyer, Sep 22, 2003
    #16
  17. Steve Zimmerman <> wrote:

    >Ravi wrote:
    >> #define A B
    >> #define B A
    >>
    >> main()
    >> {
    >> int A=5;
    >> float B=6.0;
    >> printf("\n %d %f",A,B);
    >> printf(" %d %f",B,A);
    >> }
    >>
    >> Take a look at this program. What is the output?
    >> Is it implementation dependent?
    >>
    >> Do you think this question aim's at analising a person's C skills?
    >> (It was asked in a Technical skill paper)
    >>

    >
    >Thank you for this post, Ravi.
    >
    >Output: 5 6.000000 0 0.000000
    >(There is one space before the 5.)


    And some small town in southern North Dakota being blown up. =%O

    >
    >I don't know if it's implementation dependent.


    It is. Every single bit of it. Seriously.

    >
    >The code that you cite from the technical skill paper is referred to
    >as "spaghetti code" by _The New Hacker's Dictionary_. Spaghetti code
    >is code with an unnecessarily complex and tangled control structure.


    Code like this is referred to as being downright idiotic. Period.

    Regards

    Irrwahn
    --
    Close your eyes and press escape three times.
     
    Irrwahn Grausewitz, Sep 22, 2003
    #17
  18. Nick Austin <> wrote:

    >On Tue, 23 Sep 2003 00:12:57 +0530, Ravi <> wrote:
    >
    >>>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >>>
    >>>>#define A B
    >>>>#define B A
    >>>>
    >>>>main()
    >>>>{
    >>>> int A=5;
    >>>> float B=6.0;
    >>>> printf("\n %d %f",A,B);
    >>>> printf(" %d %f",B,A);
    >>>>}
    >>>

    >>
    >>Ok, I get the point. But if you were asked this question in a
    >>technical test with 4 options
    >>
    >>a) error during compilation
    >>b) goes into an infinite loop
    >>c) 5 6.000000 6 5.000000
    >>d) 5 6.000000 0 0.000000
    >>
    >>What would you choose?

    >
    >a) is a serious contender, but the examiner probably expects d).
    >
    >The question is obviously flawed for not including:
    >
    >e) outputs only a single newline.
    >

    As well as:

    f) most certainly invokes nasal demons when ran on a DeathStation 9000
    g) surely you're joking, Mr. employer
    h) /What/ the /heck/ is /that/?!?
    i) May I have another cup of tea? It's gonna be a loooong answer...
    j) Uck!
    h) Well, ...

    Alright, I stop it now; this list could be continued ad infinitum.

    Irrwahn
    --
    My other computer is a abacus.
     
    Irrwahn Grausewitz, Sep 22, 2003
    #18
  19. Ravi

    Nick Austin Guest

    On Mon, 22 Sep 2003 19:57:30 GMT, Martin Ambuhl
    <> wrote:

    >Nick Austin wrote:
    >
    >> On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >>
    >>
    >>>#define A B
    >>>#define B A
    >>>
    >>>main()
    >>>{
    >>> int A=5;
    >>> float B=6.0;
    >>> printf("\n %d %f",A,B);

    >>
    >>
    >> Undefined behavior.

    >
    >Balony. Printing an int with %d and a float with %f is just fine.


    So an extern int printf(const char *, ...); is not required?

    Nick
     
    Nick Austin, Sep 22, 2003
    #19
  20. Nick Austin wrote:
    > On Tue, 23 Sep 2003 00:12:57 +0530, Ravi <> wrote:
    >
    >
    >>>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <> wrote:
    >>>
    >>>
    >>>>#define A B
    >>>>#define B A
    >>>>
    >>>>main()
    >>>>{
    >>>> int A=5;
    >>>> float B=6.0;
    >>>> printf("\n %d %f",A,B);
    >>>> printf(" %d %f",B,A);
    >>>>}
    >>>

    >>Ok, I get the point. But if you were asked this question in a
    >>technical test with 4 options
    >>
    >>a) error during compilation
    >>b) goes into an infinite loop
    >>c) 5 6.000000 6 5.000000
    >>d) 5 6.000000 0 0.000000
    >>
    >>What would you choose?

    >
    >
    > a) is a serious contender, but the examiner probably expects d).
    >

    I don't get it. Why would d) be expected ?

    --
    Bertrand Mollinier Toublet
    Currently looking for employment in the San Francisco Bay Area
    http://www.bmt.dnsalias.org/employment
     
    Bertrand Mollinier Toublet, Sep 22, 2003
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mono
    Replies:
    1
    Views:
    331
    David Waz...
    Jul 4, 2003
  2. Ray Dixon [MVP]

    Re: Your opinion about stored procedures

    Ray Dixon [MVP], Jul 25, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    386
    Peter Gossmann
    Jul 26, 2003
  3. Jerry

    Please share your opinion with me.

    Jerry, Aug 3, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    316
    Rajeev Soni
    Aug 4, 2003
  4. Martin Feuersteiner
    Replies:
    2
    Views:
    1,213
  5. Miguel Dias Moura
    Replies:
    0
    Views:
    379
    Miguel Dias Moura
    Feb 2, 2006
Loading...

Share This Page