Welcome, Register for free! or Login below:
EduGeek.net RSS Feeds Register FAQ Members Social Groups User Map Calendar Search Today's Posts Mark Forums Read

Go Back   EduGeek.net Forums > Coding and Web Development > Coding
Reply
 
LinkBack Thread Tools Search Thread Language
Sponsored Links
Old 15-07-2008, 11:18 AM   #1
 
Pashers's Avatar
 
Join Date: May 2008
Location: Cheshire
Posts: 17
uk uk england
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Power: 2 Pashers is on a distinguished road
Default 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
  Reply With Quote
Old 15-07-2008, 11:34 AM   #2
 
el8linuxel8's Avatar
 
Join Date: Nov 2007
Location: Preston
Posts: 98
uk
Thanks: 2
Thanked 4 Times in 4 Posts
Rep Power: 3 el8linuxel8 is on a distinguished road
Default

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; 15-07-2008 at 11:39 AM.. Reason: completed!
  Reply With Quote
Old 15-07-2008, 11:39 AM   #3
 
Jona's Avatar
 
Join Date: May 2007
Location: Aberystwyth
Posts: 419
uk uk wales
Thanks: 7
Thanked 42 Times in 42 Posts
Rep Power: 11 Jona has a spectacular aura aboutJona has a spectacular aura aboutJona has a spectacular aura about
Default

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.....?
  Reply With Quote
Old 15-07-2008, 11:44 AM   #4
 
el8linuxel8's Avatar
 
Join Date: Nov 2007
Location: Preston
Posts: 98
uk
Thanks: 2
Thanked 4 Times in 4 Posts
Rep Power: 3 el8linuxel8 is on a distinguished road
Default

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
  Reply With Quote
The Following User Says Thank You to el8linuxel8 For This Useful Post:
Jona (15-07-2008)
Old 15-07-2008, 11:45 AM   #5
 
powdarrmonkey's Avatar
 
Join Date: Feb 2008
Location: Alcester, Warwickshire
Posts: 1,078
uk
Thanks: 58
Thanked 104 Times in 87 Posts
Rep Power: 22 powdarrmonkey is a glorious beacon of lightpowdarrmonkey is a glorious beacon of lightpowdarrmonkey is a glorious beacon of lightpowdarrmonkey is a glorious beacon of lightpowdarrmonkey is a glorious beacon of lightpowdarrmonkey is a glorious beacon of light
Default

Damn, I was nearly there! My C++ is extremely rusty.
  Reply With Quote
Old 15-07-2008, 11:50 AM   #6
 
blacksheep's Avatar
 
Join Date: Nov 2007
Location: Wales, UK
Posts: 103
uk
Thanks: 1
Thanked 3 Times in 3 Posts
Rep Power: 3 blacksheep is on a distinguished road
Default

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
  Reply With Quote
Old 15-07-2008, 11:51 AM   #7
 
blacksheep's Avatar
 
Join Date: Nov 2007
Location: Wales, UK
Posts: 103
uk
Thanks: 1
Thanked 3 Times in 3 Posts
Rep Power: 3 blacksheep is on a distinguished road
Default

just typing this as you posted
  Reply With Quote
Old 15-07-2008, 11:52 AM   #8
 
el8linuxel8's Avatar
 
Join Date: Nov 2007
Location: Preston
Posts: 98
uk
Thanks: 2
Thanked 4 Times in 4 Posts
Rep Power: 3 el8linuxel8 is on a distinguished road
Default

I wouldnt run random C code as root mate
  Reply With Quote
Old 15-07-2008, 11:58 AM   #9
 
blacksheep's Avatar
 
Join Date: Nov 2007
Location: Wales, UK
Posts: 103
uk
Thanks: 1
Thanked 3 Times in 3 Posts
Rep Power: 3 blacksheep is on a distinguished road
Default

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..
  Reply With Quote
Old 09-09-2008, 01:40 PM   #10
 
Friez's Avatar
 
Join Date: Dec 2006
Posts: 762
Thanks: 13
Thanked 9 Times in 9 Posts
Rep Power: 10 Friez will become famous soon enoughFriez will become famous soon enough
Default

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")){} }
  Reply With Quote
Reply

Register now for FREE and post messages!


Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Birthday:      
Image Verification
  I agree to forum rules 

Similar Threads
Thread Thread Starter Forum Replies Last Post
Test-Um Ric_ Recommended Suppliers 15 02-02-2007 10:28 AM



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search Thread
Search Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 01:31 AM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Copyright EduGeek.net