Jump to content

Recommended Posts

Posted

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 :D

Posted (edited)

Pretty sure you can do it with in the int main() definition..let me think!

 

there:

 

#include

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

Edited by el8linuxel8
completed!
Posted

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:

#include 
int main(int argc, char **argv)
{
if (printf("Hello Edugeek\n")) {}
}

Should work.....?

Guest blacksheep
Posted

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

Guest blacksheep
Posted
just typing this as you posted :)
Guest blacksheep
Posted

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.. :)

  • 1 month later...
Posted

#include 
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:

 

#include 
void main(){ if(printf("Hello World\n")){} }

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...