473,382 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Printing "Hello World" in C programming language.

Hi all,
Could anyone please help me to print "Hello World" in C programming language without including any code inside main function

Regards.
Dec 12 '06 #1
13 6490
nickyeng
254 100+
main()
{
printf("hello, world\n");
}

like this?

Regards,
Nicky Eng.
Dec 12 '06 #2
main()
{
printf("hello, world\n");
}

like this?

Regards,
Nicky Eng.
Sorry fren, there should be no code inside the function main. So you can't include that printf statement inside the main function.

Regards.
Dec 12 '06 #3
nickyeng
254 100+
try class :
Expand|Select|Wrap|Line Numbers
  1. class Sample
  2. {
  3.        public:
  4.                Sample() { cout <<"Hello;" ; }
  5. };
  6.  
  7.  
  8. Sample S;
  9.  
  10. void main(void)
  11. {
  12. }
  13.  
  14.  
Dec 12 '06 #4
drhowarddrfine
7,435 Expert 4TB
But that's C++, not C.
Dec 12 '06 #5
Ganon11
3,652 Expert 2GB
This must be one of the weirdest (and possibly most pointless) problems I have seen.

I have no idea.
Dec 12 '06 #6
r035198x
13,262 8TB
This must be one of the weirdest (and possibly most pointless) problems I have seen.

I have no idea.
I hope it's possible
Dec 12 '06 #7
Coldfire
289 100+
I hope it's possible
i think it would work.

replace in the above sample (with constructor)
> class with struct
> "cout" with appropriate "printf" statement
...........thats it

i havnt tried though
Dec 12 '06 #8
r035198x
13,262 8TB
i think it would work.

replace in the above sample (with constructor)
> class with struct
> "cout" with appropriate "printf" statement
...........thats it

i havnt tried though
You mean to call a method inside a struct declaration?
Dec 12 '06 #9
nickyeng
254 100+
why not the thread starter searching in searc engine(google.com) first, and try the sample there...
Dec 12 '06 #10
Coldfire
289 100+
You mean to call a method inside a struct declaration?
yes...may be..i mean this
struct Sample
{
public:
Sample() {
printf("Hello World");
}
};


Sample S;

void main(void)
{
}
Dec 12 '06 #11
r035198x
13,262 8TB
yes...may be..i mean this
struct Sample
{
public:
Sample() {
printf("Hello World");
}
};


Sample S;

void main(void)
{
}
Works alright. I wonder when it might come in handy...
Dec 13 '06 #12
Banfa
9,065 Expert Mod 8TB
yes...may be..i mean this
struct Sample
{
public:
Sample() {
printf("Hello World");
}
};


Sample S;

void main(void)
{
}
This is still C++ not C, I get these errors

c:\myprojects\consoletester\consoletester.c(3) : error C2061: syntax error : identifier 'public'
c:\myprojects\consoletester\consoletester.c(7) : error C2059: syntax error : '}'
c:\myprojects\consoletester\consoletester.c(10) : error C2061: syntax error : identifier 'S'
c:\myprojects\consoletester\consoletester.c(10) : error C2059: syntax error : ';'


The answer is that in C it is not possible, the only thing you can do in C or C++ without putting code in main is declare variables. In C++ you can declare a class which will envoke it's constructor (and in fact could envoke the whole program) but in C there is no way that declaring a variable envokes any user code.
Dec 14 '06 #13
r035198x
13,262 8TB
This is still C++ not C, I get these errors

c:\myprojects\consoletester\consoletester.c(3) : error C2061: syntax error : identifier 'public'
c:\myprojects\consoletester\consoletester.c(7) : error C2059: syntax error : '}'
c:\myprojects\consoletester\consoletester.c(10) : error C2061: syntax error : identifier 'S'
c:\myprojects\consoletester\consoletester.c(10) : error C2059: syntax error : ';'


The answer is that in C it is not possible, the only thing you can do in C or C++ without putting code in main is declare variables. In C++ you can declare a class which will envoke it's constructor (and in fact could envoke the whole program) but in C there is no way that declaring a variable envokes any user code.
Gosh, I ran it on a C++ compiler
Dec 14 '06 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ME | last post by:
I am trying to find a prewritten method for converting a string like this:"Hello World" to this "Hello\sWorld". I plan to use it to build a regular expression. Specifically I am looking for a...
6
by: Matthew | last post by:
How would I go about creating a simple "hello world" program that will run in Unix. I am using MS Visual C++.
13
by: Hans | last post by:
Hello, Thanks for all your response on my question about signed/unsigned chars. The problem is this: I want to use the char array for a ArrayLookup, so I need to convert char to unsigned int....
33
by: ankursinha | last post by:
Hi, Is it possible to write a C program that prints "Hello World" on screen without having a single semi-colon in the entire program? The extra constraint here is that u r not allowed to use...
42
by: Prashanth Badabagni | last post by:
Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
4
by: arnuld | last post by:
i am learning C and doing the exercise 1-1 of K&R2, where K&R ask to remove some parts of programme and experiment with error, so here i go: #include <stdio.h> int main () { printf('hello...
3
by: amanjsingh | last post by:
I want to know what is the origin of Hello World program and who wrote it, what language it was written in and why was Hello World chosen as a phrase? Thanks a lot AJ
0
by: Gerardo Herzig | last post by:
Hi all. Im having some "problems" with a small concurrent plpython function. Based on a small example about concurrent programming, there is some code which works fine under python: #!...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.