C hello world example

quen89

Newbie
Joined
Dec 7, 2012
Messages
1
Reaction score
0
[h=2]C hello world example[/h]
#include <stdio.h> int main() { printf("Hello world\n"); return 0; }
[h=2]Hello world program in c[/h] We may store "hello world" in a character array and then print it.

#include <stdio.h> int main() { char string[] = "Hello World"; printf("%s\n", string); return 0; }
 
If you're interested, I have a lot of code I wrote years back that deals with various networking protocols using raw sockets (assuming you're on linux).
 
yup, try to improve logic and understanding over the language.
 
This is just the simplest and basic program in C++. You have to go in functions loops, nested, while and if else ladder. Try to do programming in daily basis.
 
You could also declare a typedef so that you can use the word "string" instead of having to make a char array every time.
 
hi....
we can replace "int main()" to "void main()"..and remove return statement..
 
this is pretty basic. Increase the difficulty level and go advance. Only then will you be able to truly accomplish something.
 
Why the heck store it in an array?

EDIT: OK got it now, I didn't notice that char data type.
 
Last edited:
Well, using char array is pretty useless, you could just use a string type variable.
 
Well, you are doing a good job and can you please tell me which compiler are you using to execute the program because i write the same code but DEV C++ compiler is not working on my notebook.
 
As a compiler BerliOs compiler is good, with that use code blocks IDE
 
read this a few days back , tough unrelated but still funny and mind boggling
Enjoy !!!
Code:
https://www.gnu.org/fun/jokes/helloworld.html
High School/Jr. High

10 PRINT "HELLO WORLD"
20 END
First year in College

program Hello(input, output)
begin
writeln('Hello World')
end.
Senior year in College

(defun hello
(print
(cons 'Hello (list 'World))))
New professional

#include <stdio.h>

void main(void)
{
char *message[] = {"Hello ", "World"};
int i;
for(i = 0; i < 2; ++i)
printf("%s", message);
printf("\n");
}
Seasoned professional

#include <iostream.h>
#include <string.h>
class string
{
private:
int size;
char *ptr;
public:
string() : size(0), ptr(new char('\0')) {}
string(const string &s) : size(s.size)
{
ptr = new char[size + 1];
strcpy(ptr, s.ptr);
}
~string()
{
delete [] ptr;
}
friend ostream &operator <<(ostream &, const string &);
string &operator=(const char *);
};

ostream &operator<<(ostream &stream, const string &s)
{
return(stream << s.ptr);
}
string &string::operator=(const char *chrs)
{
if (this != &chrs)
{
delete [] ptr;
size = strlen(chrs);
ptr = new char[size + 1];
strcpy(ptr, chrs);
}
return(*this);
}
int main()
{
string str;
str = "Hello World";
cout << str << endl;
return(0);
}
System Administrator

#include <stdio.h>
#include <stdlib.h>
main()
{
char *tmp;
int i=0;
/* on y va bourin */
tmp=(char *)malloc(1024*sizeof(char));
while (tmp="Hello Wolrd"[i++]);
/* Ooopps y'a une infusion ! */
i=(int)tmp[8];
tmp[8]=tmp[9];
tmp[9]=(char)i;
printf("%s\n",tmp);
}
Apprentice Hacker

#!/usr/local/bin/perl
$msg="Hello, world.\n";
if ($#ARGV >= 0) {
while(defined($arg=shift(@ARGV))) {
$outfilename = $arg;
open(FILE, ">" . $outfilename) || die "Can't write $arg: $!\n";
print (FILE $msg);
close(FILE) || die "Can't close $arg: $!\n";
}
} else {
print ($msg);
}
1;
Experienced Hacker

#include <stdio.h>
#include <string.h>
#define S "Hello, World\n"
main(){exit(printf(S) == strlen(S) ? 0 : 1);}
Seasoned Hacker

% cc -o a.out ~/src/misc/hw/hw.c
% a.out
Hello, world.
Guru Hacker

% cat
Hello, world.
New Manager (do you remember?)

10 PRINT "HELLO WORLD"
20 END
Middle Manager

mail -s "Hello, world." bob@b12
Bob, could you please write me a program that prints "Hello, world."?
I need it by tomorrow.
^D
Senior Manager

% zmail jim
I need a "Hello, world." program by this afternoon.
Chief Executive

% letter
letter: Command not found.
% mail
To: ^X ^F ^C
% help mail
help: Command not found.
% damn!
!: Event unrecognized
% logout
Research Scientist

PROGRAM HELLO
PRINT *, 'Hello World'
END
Older research Scientist

WRITE (6, 100)
100 FORMAT (1H ,11HHELLO WORLD)
CALL EXIT END
 
I am student of computer science and these kinds of small programs i daily write in my programing class. I use the Dev C++ compiler to execute the program and if you are familiar with other compiler then mention here.
 
Back
Top