Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Tricky , yet interesting question

 
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greeting ranchers

I was asked an interesting question about programming recently and I want to share with you all.

"Without using any semi-colons in the entire code write a simple application in C/C++ which simply prints "Hello World" on the console "

Of-course I know the answer but I want to see your responses first before I share the solution
 
lowercase baba
Posts: 13014
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a better question...

Why would you want to?
 
Saif Asif
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No particular reason . Of-course no one wants to do that , it was just a challenge that my friend gave to all of us and we were coming will all sorts of weird solutions , in the end he showed us how to do it So I thought to ask here on the ranch as well
 
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saif Asif wrote:No particular reason . Of-course no one wants to do that , it was just a challenge that my friend gave to all of us and we were coming will all sorts of weird solutions , in the end he showed us how to do it So I thought to ask here on the ranch as well



Since this is a java site, wouldn't the question be better if the challenge was for java?

Henry
 
Henry Wong
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And BTW, here is the solution in Java...



For C/C++, I would try to do something similar with the C preprocessor.

Henry
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class App {
static{
if( System.out.append("hello world").checkError() ){}

}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}


This is how you do it in Java
 
Saif Asif
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
Since this is a java site, wouldn't the question be better if the challenge was for java?



That's an even better idea !

 
Saif Asif
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
And BTW, here is the solution in Java...



For C/C++, I would try to do something similar with the C preprocessor.

Henry



You are using the Unicode for semi-colon here, but the requirement was to avoid the use of a semi-colon at all . Still I like your approach !



Myke wrote:



This is how you do it in Java



Great approach Mike .

The solution in C is similar to this one, i.e to wrap the console writer within an if statement and an empty if block ! And truly your code is without any semi-colon at all ! Great !
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow... great and thanks for sharing
reply
    Bookmark Topic Watch Topic
  • New Topic