print "foo" without using ;

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rajesh

    print "foo" without using ;

    I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
    of ways to achive it.
    mine sol. was....

    int main()
    {
    if(printf("foo" ))
    { ; }
    else
    { ; }

    return(0);
    }

    (don't do tht stupid #define )

  • Chris Dollin

    #2
    Re: print "foo&qu ot; without using ;

    Rajesh wrote:
    [color=blue]
    > I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
    > of ways to achive it.
    > mine sol. was....
    >
    > int main()
    > {
    > if(printf("foo" ))
    > { ; }
    > else
    > { ; }
    >
    > return(0);
    > }
    >
    > (don't do tht stupid #define )[/color]

    I hate to point this out [1], but your solution contains not
    zero semicolons, but *three*.

    As far as I can tell, any "solution" is at best stylistically
    unsatisfactory.

    --
    Chris "electric hedgehog" Dollin
    Stross won one! Farah won one! Langford won TWO!

    Comment

    • Rajesh

      #3
      Re: print "foo&qu ot; without using ;

      sorry for tht It was just a too much typo.... used too much to
      semicolons

      neglect that 'int main()' use 'void main()' and dike out those ';' in
      if...else plz.
      it works.

      once again sorry for tht typo I swear :(

      Comment

      • Clark S. Cox III

        #4
        Re: print "foo&qu ot; without using ;

        On 2005-08-23 10:18:05 -0400, "Rajesh" <rajeshsbhide21 11@yahoo.co.in> said:
        [color=blue]
        > I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
        > of ways to achive it.
        > mine sol. was....[/color]

        First, why on earth are you abbreviating so much? I don't even know
        what you mean by "imp."
        Second, is it really too hard to spell the actual subject out in your message?
        [color=blue]
        > int main()
        > {
        > if(printf("foo" ))
        > { ; }
        > else
        > { ; }
        >
        > return(0);
        > }[/color]

        Um, you failed. I count three semicolons.
        [color=blue]
        > (don't do tht stupid #define )[/color]

        What stupid #define?

        Try:

        #include <stdio.h>
        int main()
        {
        if(puts("foo")) {}
        }

        or

        #include <stdio.h>
        int main()
        {
        while(puts("foo "),0) {}
        }

        or

        #include <stdio.h>
        int main()
        {
        switch(puts("fo o"))
        {
        default: {}
        }
        }


        or any of the variations on that theme.

        --
        Clark S. Cox, III
        clarkcox3@gmail .com

        Comment

        • Carlos

          #5
          Re: print &quot;foo&qu ot; without using ;



          Rajesh wrote:[color=blue]
          > sorry for tht It was just a too much typo.... used too much to
          > semicolons
          >
          > neglect that 'int main()' use 'void main()' and dike out those ';' in
          > if...else plz.
          > it works.
          >
          > once again sorry for tht typo I swear :(
          >[/color]

          I suspect that your garbage English isn't due to typos.

          Comment

          • Richard Bos

            #6
            Re: print &quot;foo&qu ot; without using ;

            Clark S. Cox III <clarkcox3@gmai l.com> wrote:
            [color=blue]
            > On 2005-08-23 10:18:05 -0400, "Rajesh" <rajeshsbhide21 11@yahoo.co.in> said:
            >[color=green]
            > > I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
            > > of ways to achive it.
            > > mine sol. was....[/color]
            >
            > First, why on earth are you abbreviating so much?[/color]

            Because it's K3wLl!1!
            [color=blue]
            > Second, is it really too hard to spell the actual subject out in your message?[/color]

            In fact, I doubt a Microsoft interviewer used (or, for that matter,
            understood) non-Microsoft-style shell variables such as $SUBJECT.
            [color=blue]
            > Um, you failed.[/color]

            From the word Go, never mind the semi-colons.
            [color=blue]
            > Try:
            >
            > #include <stdio.h>
            > int main()
            > {
            > if(puts("foo")) {}
            > }
            >
            > or[/color]

            Or rather, don't try. I wouldn't consider hiring anyone whose first and
            preferably only answer was "What on earth for? I prefer to write better
            code than that." I wouldn't consider working for a company that asked
            such interview questions. I'd rather flip burgers; at least McDonalds is
            up front about not requiring more than imbecility from its staff.

            Richard

            Comment

            • Kenneth Brody

              #7
              Re: print &quot;foo&qu ot; without using ;

              Rajesh wrote:[color=blue]
              >
              > I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
              > of ways to achive it.
              > mine sol. was....
              >
              > int main()
              > {
              > if(printf("foo" ))
              > { ; }
              > else
              > { ; }
              >
              > return(0);
              > }
              >
              > (don't do tht stupid #define )[/color]

              Well, I see three semicolons in your code.

              How about:

              10 PRINT "foo"
              20 END

              Or:

              <html><body>foo </body></html>

              Or:

              (defun foo ()
              (format t "foo~%"))

              Or:

              ++++++++++[>++++>+++++++++ +>+++++++<<<-][color=blue][color=green][color=darkred]
              >>>++.<+.++++++ +..+++.<++++.<+ ++[>----<-]>.[/color][/color]
              >++++++++.--------.+++.------.--------.<<+++[>++++<-]>++.<++++++++++ .[/color]


              Oh, you wanted a solution in C. :-)

              #include <stdio.h>

              int main(int argc,char *argv[])
              {
              if ( printf("foo\n") )
              {
              }
              }

              --
              +-------------------------+--------------------+-----------------------------+
              | Kenneth J. Brody | www.hvcomputer.com | |
              | kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
              +-------------------------+--------------------+-----------------------------+
              Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>

              Comment

              • akarl

                #8
                Re: print &quot;foo&qu ot; without using ;

                Rajesh wrote:[color=blue]
                > I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
                > of ways to achive it.
                > mine sol. was....
                >
                > int main()
                > {
                > if(printf("foo" ))
                > { ; }
                > else
                > { ; }
                >
                > return(0);
                > }
                >
                > (don't do tht stupid #define )
                >[/color]

                It's impossible to write any complete program without using semicolon
                since the `main' function requires a return statement.

                August

                Comment

                • Mark

                  #9
                  Re: print &quot;foo&qu ot; without using ;

                  "akarl" <fusionfive@com hem.se> wrote in message
                  news:GSIOe.1448 45$dP1.500706@n ewsc.telia.net. ..[color=blue]
                  > Rajesh wrote:[color=green]
                  >> I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
                  >> of ways to achive it.
                  >> mine sol. was....
                  >>
                  >> int main()
                  >> {
                  >> if(printf("foo" ))
                  >> { ; }
                  >> else
                  >> { ; }
                  >>
                  >> return(0);
                  >> }
                  >>
                  >> (don't do tht stupid #define )
                  >>[/color]
                  >
                  > It's impossible to write any complete program without using semicolon
                  > since the `main' function requires a return statement.[/color]

                  Do you have a copy of the standard (or final draft?)

                  5.1.2.2.3 - Program termination
                  .... 9) reaching the } that terminated the main function returns a value of 0


                  Comment

                  • Keith Thompson

                    #10
                    Re: print &quot;foo&qu ot; without using ;

                    akarl <fusionfive@com hem.se> writes:[color=blue]
                    > Rajesh wrote:[color=green]
                    >> I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
                    >> of ways to achive it.
                    >> mine sol. was....
                    >> int main()
                    >> {
                    >> if(printf("foo" ))
                    >> { ; }
                    >> else
                    >> { ; }
                    >> return(0);
                    >> }
                    >> (don't do tht stupid #define )
                    >>[/color]
                    >
                    > It's impossible to write any complete program without using semicolon
                    > since the `main' function requires a return statement.[/color]

                    No, it doesn't. In C99, falling off the end of main() is equivalent
                    to executing "return 0;" (which is a misfeature IMHO). Even in C90,
                    you can use exit() rather than return.

                    The original question is stupid, but here's a solution anyway:

                    #include <stdio.h>
                    #include <stdlib.h>
                    int main(void)
                    {
                    if (puts("hello"), exit(0),0){}
                    }

                    --
                    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                    We must do something. This is something. Therefore, we must do this.

                    Comment

                    • Walter Roberson

                      #11
                      Re: print &quot;foo&qu ot; without using ;

                      In article <lnd5o44juj.fsf @nuthaus.mib.or g>,
                      Keith Thompson <kst-u@mib.org> wrote:[color=blue]
                      >akarl <fusionfive@com hem.se> writes:[color=green]
                      >> Rajesh wrote:[color=darkred]
                      >>> I was informed tht $SUBJECT was asked in M$ interview.[/color][/color][/color]
                      [color=blue]
                      >No, it doesn't. In C99, falling off the end of main() is equivalent
                      >to executing "return 0;" (which is a misfeature IMHO). Even in C90,
                      >you can use exit() rather than return.[/color]
                      [color=blue]
                      >The original question is stupid, but here's a solution anyway:[/color]
                      [color=blue]
                      >#include <stdio.h>
                      >#include <stdlib.h>
                      >int main(void)
                      >{
                      > if (puts("hello"), exit(0),0){}
                      >}[/color]

                      If one supposes C89, then what would be the exit status if the puts()
                      fails?

                      Perhaps something like

                      if (puts("foo") && (exit(0),0) || (exit(0),0) ) {}

                      or

                      if ( puts("foo") ? exit(0),0 : exit(0),0 ) {}
                      --
                      "I will speculate that [...] applications [...] could actually see a
                      performance boost for most users by going dual-core [...] because it
                      is running the adware and spyware that [...] are otherwise slowing
                      down the single CPU that user has today" -- Herb Sutter

                      Comment

                      • Emmanuel Delahaye

                        #12
                        Re: print &quot;foo&qu ot; without using ;

                        akarl wrote on 23/08/05 :[color=blue]
                        > It's impossible to write any complete program without using semicolon since
                        > the `main' function requires a return statement.[/color]

                        It's possible in C99.


                        --
                        Emmanuel
                        The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
                        The C-library: http://www.dinkumware.com/refxc.html

                        ..sig under repair


                        Comment

                        • Keith Thompson

                          #13
                          Re: print &quot;foo&qu ot; without using ;

                          roberson@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:[color=blue]
                          > In article <lnd5o44juj.fsf @nuthaus.mib.or g>,
                          > Keith Thompson <kst-u@mib.org> wrote:[color=green]
                          >>akarl <fusionfive@com hem.se> writes:[color=darkred]
                          >>> Rajesh wrote:
                          >>>> I was informed tht $SUBJECT was asked in M$ interview.[/color][/color]
                          >[color=green]
                          >>No, it doesn't. In C99, falling off the end of main() is equivalent
                          >>to executing "return 0;" (which is a misfeature IMHO). Even in C90,
                          >>you can use exit() rather than return.[/color]
                          >[color=green]
                          >>The original question is stupid, but here's a solution anyway:[/color]
                          >[color=green]
                          >>#include <stdio.h>
                          >>#include <stdlib.h>
                          >>int main(void)
                          >>{
                          >> if (puts("hello"), exit(0),0){}
                          >>}[/color]
                          >
                          > If one supposes C89, then what would be the exit status if the puts()
                          > fails?[/color]

                          The exit status is 0 regardless of what puts() returns. The comma
                          operator imposes a sequence point and a left-to-right evaluation order
                          on its operands, but it doesn't short-circuit; both operands are
                          always evaluated.

                          --
                          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                          We must do something. This is something. Therefore, we must do this.

                          Comment

                          • Walter Roberson

                            #14
                            Re: print &quot;foo&qu ot; without using ;

                            In article <ln64tw4h1m.fsf @nuthaus.mib.or g>,
                            Keith Thompson <kst-u@mib.org> wrote:[color=blue][color=green][color=darkred]
                            >>> if (puts("hello"), exit(0),0){}[/color][/color][/color]
                            [color=blue]
                            >The exit status is 0 regardless of what puts() returns. The comma
                            >operator imposes a sequence point and a left-to-right evaluation order
                            >on its operands, but it doesn't short-circuit; both operands are
                            >always evaluated.[/color]

                            Ah, right, I should have twigged onto that. Thanks.
                            --
                            The rule of thumb for speed is:

                            1. If it doesn't work then speed doesn't matter. -- Christian Bau

                            Comment

                            • akarl

                              #15
                              Re: print &quot;foo&qu ot; without using ;

                              Mark wrote:[color=blue]
                              > "akarl" <fusionfive@com hem.se> wrote in message
                              > news:GSIOe.1448 45$dP1.500706@n ewsc.telia.net. ..
                              >[color=green]
                              >>Rajesh wrote:
                              >>[color=darkred]
                              >>>I was informed tht $SUBJECT was asked in M$ interview. Real imp. is no.
                              >>>of ways to achive it.
                              >>>mine sol. was....
                              >>>
                              >>>int main()
                              >>>{
                              >>> if(printf("foo" ))
                              >>> { ; }
                              >>> else
                              >>> { ; }
                              >>>
                              >>>return(0);
                              >>>}
                              >>>
                              >>>(don't do tht stupid #define )
                              >>>[/color]
                              >>
                              >>It's impossible to write any complete program without using semicolon
                              >>since the `main' function requires a return statement.[/color]
                              >
                              >
                              > Do you have a copy of the standard (or final draft?)
                              >
                              > 5.1.2.2.3 - Program termination
                              > ... 9) reaching the } that terminated the main function returns a value of 0[/color]

                              OK, I didn't know that. Seems like quite a few people in this group has
                              complained when someone has posted a main function lacking a return
                              statement. Hence my impression of it being mandatory. Without a return
                              statement we can of course do something like

                              #include <stdio.h>

                              int main(void)
                              {
                              if (puts("foo")) {}
                              }


                              August

                              Comment

                              Working...