Printing "hello , wolrd" with out using semicolon

  • Thread starter Prashanth Badabagni
  • Start date
P

Prashanth Badabagni

Hi,
Can any body tell me how to print "hello,world" with out using semicolon



Thanks in advance ..
Bye
Prashanth Badabagni
 
M

Martin Ambuhl

Prashanth said:
Hi,
Can any body tell me how to print "hello,world" with out using semicolon

Yes. Now ask someone to help you search the archives at groups.google.com.
 
M

madhukar_bm

Hi,
Can any body tell me how to print "hello,world" with out using semicolon



Thanks in advance ..
Bye
Prashanth Badabagni

#include<stdio.h>

void main()
{
if(printf("hello world\n"))
}
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

madhukar_bm said:
(e-mail address removed) (Prashanth Badabagni) wrote in message


#include<stdio.h>
Whilst this line, of itself, does not contain a semicolon, it's actions
effectively insert many other lines (some of which /may/ contain semicolons)
into the source code. This is line technically satisfies the OPs requirement,
but operationally may not.
void main()

In a hosted implementation, main() returns int, and must be declared so, unless
an implementation-specific extension is in use. No such extension has been
mentioned, and the OPs question does not specify an unhosted implementation, so
this line is suspect.
{
if(printf("hello world\n"))

An if() statement requires the inclusion of at least one additional statement,
to be executed when the if() evaluates to true. Your code above is a syntax
error at the very least.

Also, main() returns int. Ensure that int is returned.

Alternatively, given a C99-compliant compiler for a hosted environment...

int main(void)
{
if (printf("hello, world\n")) {}
}

/*
** In the absence of a prototype, the printf() function is
** assumed to return int and to take as its argument
** a single string. Both of these assumptions are consistant
** with the function declaration found in stdio.h, and thus
** while fragile and technically suspect, is acceptable.
** The absence of the stdio include eliminates the possibility
** of included semicolons, and satisfies the argument against
** the use of an included header in /this/ program.
**
** The if() statement is satisfied by an empty compound statement,
** correcting the previous poster's syntax error.
**
** Finally, as the main() function is defined as returning int, and
** this is specified to be compiled in a C99-compliant compiler for
** a hosted environment, the language environment will ensure that
** an appropriate int value is returned from main() in the absence
** of an explicit value return.
*/





- --
Lew Pitcher
IT Consultant, Enterprise Application Architecture,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFAljs6agVFX4UWr64RAhvyAKCqIs5ZG0a3SOnnzjBhIyVtXgcgqACePvBS
mcMg7GKVMllpnd7ezuwi+g4=
=8u1d
-----END PGP SIGNATURE-----
 
J

Jeremy Yallop

Lew said:
Alternatively, given a C99-compliant compiler for a hosted environment...

int main(void)
{
if (printf("hello, world\n")) {}
}

No C99-compliant compiler is required to accept this program, since
there is no declaration in scope for printf().
/*
** In the absence of a prototype, the printf() function is
** assumed to return int and to take as its argument
** a single string. Both of these assumptions are consistant
** with the function declaration found in stdio.h, and thus
** while fragile and technically suspect, is acceptable.

No, calling a function that accepts a variable number of arguments
through a function pointer of non-variadic type invokes undefined
behaviour.

6 If the expression that denotes the called function has a type that
does not include a prototype, the integer promotions are performed
on each argument, and arguments that have type float are promoted
to double. [...] If the function is defined with a type that
includes a prototype, and either the prototype ends with an
ellipsis (, ...) or the types of the arguments after promotion
are not compatible with the types of the parameters, the behavior
is undefined. [C99 6.5.2.2]

If you want to rely on an "implicit declaration" (using a C89
compiler), you can use puts() instead.

Jeremy.
 
T

Thomas Matthews

Prashanth said:
Hi,
Can any body tell me how to print "hello,world" with out using semicolon



Thanks in advance ..
Bye
Prashanth Badabagni

Besides being a homework candidate question, what useful
application does this suit?

I've never concerned myself with this kind of issue in all
my 30 years of programming.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
A

Allan Bruce

Prashanth Badabagni said:
Hi,
Can any body tell me how to print "hello,world" with out using semicolon



Thanks in advance ..
Bye
Prashanth Badabagni

why would you want to?
Allan
 
D

Darrell Grainger

Besides being a homework candidate question, what useful
application does this suit?

During an interview it could be a useful way to see of the candidate has
been lurking on comp.lang.c for the passed year or at least read the
archives. 8^)
I've never concerned myself with this kind of issue in all
my 30 years of programming.

Only 21 years but I agree. I do occasionally have to understand some
obfuscated code however. I don't write obfuscated code (at least not for
professional programming) but I have had to re-write obfuscated code.
 
D

Darrell Grainger

A very simple solution is to write a BASIC program and run it:

10 PRINT "hello,world"
20 END

Even simpler, use a word processor, type "hello,world", then use the
Print menu.

But then it would be off-topic for comp.lang.c. 8^)
 
J

Joona I Palaste

Lew Pitcher said:
Whilst this line, of itself, does not contain a semicolon, it's actions
effectively insert many other lines (some of which /may/ contain semicolons)
into the source code. This is line technically satisfies the OPs requirement,
but operationally may not.

If all that is needed is for the actual C source file not to contain
semicolons, all we need to do is:

/* file: program.c */
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}

/* file: main.c */
#include "program.c"

And then compile main.c.
 
M

Michael Wojcik

These requirements are easily satisfied with a one-line C translation
unit:

#error "hello,world"

since they don't specify that "hello,world" (or "hello , wolrd", or
other variations thereof) be printed during program execution, or
indeed that there be a program (written by the user to satisfy the
assignment) at all.

--
Michael Wojcik (e-mail address removed)

An intense imaginative activity accompanied by a psychological and moral
passivity is bound eventually to result in a curbing of the growth to
maturity and in consequent artistic repetitiveness and stultification.
-- D. S. Savage
 
R

red floyd

since they don't specify that "hello,world" (or "hello , wolrd", or
other variations thereof) be printed during program execution, or
indeed that there be a program (written by the user to satisfy the
assignment) at all.

Since there is no requriement for even a program to be written:

(from the command line)
echo "hello, world"
 
M

Michael Wojcik

Since there is no requriement for even a program to be written:

(from the command line)
echo "hello, world"

Ah, but that's not topical on c.l.c, unlike my proposal. I'm treating
group topicality as an additional, externally-imposed requirement.
 
Y

Yakov Lerner

Can any body tell me how to print "hello,world" with out using semicolon

Here is a variation: write C program to print ";"
without using semicolon, digits, double quote, and single quote.
Assume ascii.

Yakov
 
J

Joona I Palaste

Here is a variation: write C program to print ";"
without using semicolon, digits, double quote, and single quote.
Assume ascii.

Earlier, I wrote a program to print "Hello, world" without using literal
values (numbers, characters or strings) at all. It also assumed ASCII.
By combining this and various techniques presented in this thread your
problem can be solved.
 
A

Arthur J. O'Dwyer

Here is a variation: write C program to print ";"
without using semicolon, digits, double quote, and single quote.
Assume ascii.

ASCII is off-topic in comp.lang.c. I think you meant to say,
"Do not assume ASCII."

#include <stdio.h>
#include <stdlib.h>
#define Z ((int)NULL)
#define P(x) printf(#x
#define L(x) #x
#define S L(| |)[!Z]
int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f
(++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z
&&P(%c%c%d\n),S,S,Z)&&f(++i,i)){}else if(--l==Z&&P(%c/\n),S
)&&f(++i,i)){}else if(exit(Z),Z){}}int main(){if(f(Z,Z)){}}

-Arthur
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Hello everyone 0
Hello everyone ! 4
Hello Everybody 0
Hello I'm new to coding 1
bugs in c 20
Hello there ! 2
Any Ideas On This Simple Co-Prime program 1
Hello there 3

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top