1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C hello world example

Discussion in 'C, C++, C#' started by quen89, Dec 7, 2012.

  1. quen89

    quen89 Newbie

    Joined:
    Dec 7, 2012
    Messages:
    1
    Likes Received:
    0
    Home Page:
    [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; }
     
  2. Blackberry_11

    Blackberry_11 Regular Member

    Joined:
    Apr 17, 2011
    Messages:
    266
    Likes Received:
    19
    Pretty good but don' stop here ,be advance.
     
  3. RottenYellow

    RottenYellow BANNED BANNED

    Joined:
    Sep 10, 2010
    Messages:
    68
    Likes Received:
    16
    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).
     
  4. terap

    terap Newbie

    Joined:
    Dec 27, 2012
    Messages:
    11
    Likes Received:
    1
    yup, try to improve logic and understanding over the language.
     
  5. new2world

    new2world Registered Member

    Joined:
    Jan 16, 2013
    Messages:
    61
    Likes Received:
    8
    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.
     
  6. firescape27

    firescape27 Newbie

    Joined:
    Feb 9, 2013
    Messages:
    12
    Likes Received:
    0
    You could also declare a typedef so that you can use the word "string" instead of having to make a char array every time.
     
  7. johnmacklen

    johnmacklen Registered Member

    Joined:
    Apr 26, 2013
    Messages:
    52
    Likes Received:
    2
    hi....
    we can replace "int main()" to "void main()"..and remove return statement..
     
  8. rotwic

    rotwic Registered Member

    Joined:
    Nov 11, 2012
    Messages:
    78
    Likes Received:
    17
    Occupation:
    University Student
    this is pretty basic. Increase the difficulty level and go advance. Only then will you be able to truly accomplish something.
     
  9. Conor

    Conor Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,363
    Likes Received:
    5,424
    Gender:
    Male
    Location:
    South Africa
    Home Page:
  10. hameem

    hameem Elite Member

    Joined:
    Jul 21, 2011
    Messages:
    1,880
    Likes Received:
    985
    Location:
    221B Baker Street
    What's the point of this thread?
     
  11. capripio

    capripio Regular Member

    Joined:
    Dec 25, 2010
    Messages:
    248
    Likes Received:
    157
    Occupation:
    Programmer
    Location:
    127.0.0.1
    What?! Is this some kind of tutorial :p
     
  12. DarkPixel

    DarkPixel Jr. VIP Jr. VIP Premium Member

    Joined:
    Oct 4, 2011
    Messages:
    1,328
    Likes Received:
    1,239
    Location:
    ↓↓↓↓
    Home Page:
    Why the heck store it in an array?

    EDIT: OK got it now, I didn't notice that char data type.
     
    Last edited: May 27, 2013
  13. IceWizzard

    IceWizzard Newbie

    Joined:
    Jul 3, 2013
    Messages:
    15
    Likes Received:
    1
    Well, using char array is pretty useless, you could just use a string type variable.
     
  14. gregevskye

    gregevskye BANNED BANNED Jr. VIP Premium Member

    Joined:
    Jul 15, 2013
    Messages:
    309
    Likes Received:
    36
    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.
     
  15. nopme88

    nopme88 Registered Member

    Joined:
    Jul 30, 2013
    Messages:
    50
    Likes Received:
    7
    Occupation:
    Freelancer
    As a compiler BerliOs compiler is good, with that use code blocks IDE
     
  16. divok

    divok Senior Member

    Joined:
    Jul 21, 2010
    Messages:
    1,015
    Likes Received:
    634
    Location:
    http://twitter.com/divok
    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::eek:perator=(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
     
  17. David Jackson

    David Jackson Registered Member

    Joined:
    Aug 13, 2013
    Messages:
    84
    Likes Received:
    16
    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.