UMBC CMSC 201 Fall '02 CSEE | 201 | 201 F'02 | lectures | news | help

Hello World

/***************************************** ** File: hello.c ** Author: Sue Bogar ** Date: Jan 6, 1992 ** Section: 101 ** SSN: 123-45-6789 ** E-Mail: bogar@cs.umbc.edu ** ** This program prints the message "Hello, world." ** on the screen. The program is taken from the ** classic C reference text "The C Programming ** Language" by Brian Kernighan & Dennis Ritchie. *****************************************/ #include <stdio.h> int main() { printf("Hello, world.\n"); return 0; }

Compiling and running the program

linux1[72]% ls hello.c hello2.c linux1[73]% gcc -Wall -ansi hello.c linux1[74]% ls a.out hello.c hello2.c linux1[75]% a.out Hello, world. linux1[76]%

Note


Annotated hello.c

/***************************************** ** File: hello.c ** Author: Sue Bogar ** Date: Jan 6, 1992 ** Section: 101 ** SSN: 123-45-6789 ** E-Mail: bogar@cs.umbc.edu ** ** This program prints the message "Hello, world." ** on the screen. The program is taken from the ** classic C reference text "The C Programming ** Language" by Brian Kernighan & Dennis Ritchie. *****************************************/ #include <stdio.h> int main() { printf("Hello, world.\n"); return 0; }

Notes


Special Characters

The Program

/***************************************** ** File: hello2.c ** Author: Sue Bogar ** Date: Jan 6, 1992 ** Section: 101 ** SSN: 123-45-6789 ** E-Mail: bogar@cs.umbc.edu ** ** Embellishments to hello.c. *****************************************/ #include <stdio.h> int main() { printf("Mork says (in a loud voice): ") ; printf("Hello world.\n\n") ; printf("World says (whispers back): ") ; printf("@$#%%\"\\!=@&*\n") ; return 0; }

The Output

linux1[76]% gcc -Wall -ansi hello2.c linux1[77]% a.out Mork says (in a loud voice): Hello world. World says (whispers back): @$#%"\!=@&* linux1[78]%


Annotated hello2.c

/***************************************** ** File: hello2.c ** Author: Sue Bogar ** Date: Jan 6, 1992 ** Section: 101 ** SSN: 123-45-6789 ** E-Mail: bogar@cs.umbc.edu ** ** Embellishments to hello.c. *****************************************/ #include <stdio.h> int main() { printf("Mork says (in a loud voice): ") ; printf("Hello world.\n\n") ; printf("World says (whispers back): ") ; printf("@$#%%\"\\!=@&*\n") ; return 0; }

NOTE


Tradition

When Kernighan and Richie wrote the first book about the language C, they used a simple program that printed out the string "Hello, World" as the first example program.

Over the years, the traditional starting place for programming discussions has become the "Hello, World" program.

Once you can print out a string, you've mastered the mechanics of getting something to run without delving into the intricacies of getting a real program to work the way you expect it to work.


CSEE | 201 | 201 F'02 | lectures | news | help