UMBC CMSC 201
Fall '06

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

Hello World

/***************************************** ** File: hello.c ** Author: Sue Bogar ** Date: Jan 6, 1992 ** Section: 101 ** 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; }
Now that we've written hello.c using a text editor (xemacs), we will have to compile it using our compiler, gcc, before it can be run. This diagram shows the entire process:


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 ** 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 Evans ** Date: Jan 23, 2004 ** Section: 101 ** E-Mail: bogar@cs.umbc.edu ** ** This variation of hello.c employs South Park ** characters using foul language to illustrate ** how some special characters must be printed ** in C. *****************************************/ #include <stdio.h> int main() { printf("Cartman says : ") ; printf("Hello, Kyle.\n\n") ; printf("Kyle says : ") ; printf("@$#%%\"\\!=@&*\n") ; return 0; }

The Output

linux1[76]% gcc -Wall -ansi hello2.c linux1[77]% a.out Cartman says : Hello, Kyle. Kyle says : @$#%"\!=@&* linux1[78]%


Annotated hello2.c

/***************************************** ** File: hello2.c ** Author: Sue Evans ** Date: Jan 23, 2004 ** Section: 101 ** E-Mail: bogar@cs.umbc.edu ** ** This variation of hello.c employs South Park ** characters using foul language to illustrate ** how some special characters must be printed ** in C. *****************************************/ #include <stdio.h> int main() { printf("Cartman says : ") ; printf("Hello, Kyle.\n\n") ; printf("Kyle says : ") ; 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'06 | lectures | news | help

last modified on Tuesday, 22-Aug-2006 07:13:52 EDT