+ Post New Thread
Results 1 to 10 of 10
Coding Thread, Test your C++ in Coding and Web Development; Hey how's it going? For those who know C++, write a program to display "Hello World". The program must NOT ...
  1. #1

    Join Date
    May 2008
    Location
    Cheshire
    Posts
    292
    Thank Post
    48
    Thanked 27 Times in 24 Posts
    Rep Power
    18

    Test your C++

    Hey how's it going?

    For those who know C++, write a program to display "Hello World". The program must NOT contain any semi colons ( ; ).

    Good luck

  2. #2

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    Pretty sure you can do it with in the int main() definition..let me think!

    there:

    #include <stdio.h>
    int main(int argc, char *argv[printf("Hello EDUGEEK\n")]) {}
    Last edited by el8linuxel8; 15th July 2008 at 11:39 AM. Reason: completed!

  3. #3
    Jona's Avatar
    Join Date
    May 2007
    Location
    Cranleigh
    Posts
    469
    Thank Post
    14
    Thanked 50 Times in 48 Posts
    Rep Power
    23
    If your allowing the user of if statements this is defiantly possible, I think it's possible by putting it in the main() declaration as well, although I'm not sure if either will result in ANSI valid C....

    I reckon:
    Code:
    #include <stdio.h>
    int main(int argc, char **argv)
    {
    if (printf("Hello Edugeek\n")) {}
    }
    Should work.....?

  4. #4

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    josh@liberty:~$ cat temp.c;gcc temp.c -o temp;./temp
    #include <stdio.h>
    int main(int argc, char **argv)
    {
    if (printf("Hello Edugeek\n")) {}
    }

    Hello Edugeek

  5. Thanks to el8linuxel8 from:

    Jona (15th July 2008)

  6. #5

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Damn, I was nearly there! My C++ is extremely rusty.

  7. #6
    Unvalidated User
    Join Date
    Nov 2007
    Location
    the Pub
    Posts
    255
    Thank Post
    7
    Thanked 11 Times in 10 Posts
    Rep Power
    0
    Both work ok

    [root@sulaco ~]# gcc ./t.c
    [root@sulaco ~]# ./a.out
    Hello EDUGEEK
    [root@sulaco ~]# gcc ./t2.c
    [root@sulaco ~]# ./a.out
    Hello Edugeek

  8. #7
    Unvalidated User
    Join Date
    Nov 2007
    Location
    the Pub
    Posts
    255
    Thank Post
    7
    Thanked 11 Times in 10 Posts
    Rep Power
    0
    just typing this as you posted

  9. #8

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    I wouldnt run random C code as root mate

  10. #9
    Unvalidated User
    Join Date
    Nov 2007
    Location
    the Pub
    Posts
    255
    Thank Post
    7
    Thanked 11 Times in 10 Posts
    Rep Power
    0
    Is ok though as straighforward looking printf statement, unless theres some strange C hack there I cant see

    Now if it was long program or something unusual id after be careful..

    A nice script to copy bash with setuid bit set say to a users homedir, have done that before hehe..

  11. #10
    Friez's Avatar
    Join Date
    Dec 2006
    Posts
    839
    Thank Post
    22
    Thanked 22 Times in 21 Posts
    Rep Power
    23
    Quote Originally Posted by Jona View Post
    Code:
    #include <stdio.h>
    int main(int argc, char **argv)
    {
    if (printf("Hello Edugeek\n")) {}
    }
    Should work.....?
    Technically not valid as you don't return a value when you exit the main function with a declaration of main as having an int return value (Although may compile depending on the compiler used).

    I would reduce like so:

    Code:
    #include <stdio.h>
    void main(){ if(printf("Hello World\n")){} }

SHARE:
+ Post New Thread

Similar Threads

  1. Test-Um
    By Ric_ in forum Recommended Suppliers
    Replies: 15
    Last Post: 2nd February 2007, 09:28 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •