l2a hello world
TRANSCRIPT
-
7/26/2019 L2a Hello World
1/12
ddo
-
7/26/2019 L2a Hello World
2/12
#include
main()
{
printf("Hello World\n");
return 0;
ddo
-
7/26/2019 L2a Hello World
3/12
include
This includes a file called stdio.hwhich lets ususe certain commands.
stdio is short for Standard Input/Output whichmeans it has commands for input like readingfrom the keyboard and output like printing thingson the screen.
ddo
-
7/26/2019 L2a Hello World
4/12
main!
main is the name of the point where the programstarts and the brackets are there for a reason that
you will learn in the future but they ha"e to bethere.
#ll programs must ha"e a main function
ddo
-
7/26/2019 L2a Hello World
5/12
$%
The & curly brackets are used to group all thecommands together so it is known that thecommands belong to main. These curlybrackets are used "ery often in ' to groupthings together.
ddo
-
7/26/2019 L2a Hello World
6/12
printf()ello *orld+n(!,
This is the printf command and it prints te-t on the screen.The data that is to be printed is put inside brackets.
ddo
-
7/26/2019 L2a Hello World
7/12
'omments in a program are called inlinedocumentation
They should be included to e-plain the purposeof the program and describe processing steps
They do not affect how a program works
' comments can take two forms
// this comment runs to the end of the line
/* this comment runs to the terminating
symbol, even across line breaks */
ddo
-
7/26/2019 L2a Hello World
8/12
Spaces0 blank lines0 and tabs are called whitespace
*hite space is used to separate words and
symbols in a program 1-tra white space is ignored
# "alid ' program can be formatted many ways
2rograms should be formatted to enhancereadability0 using consistent indentation
ddo
-
7/26/2019 L2a Hello World
9/12
main() {
#include
// comments about the rogram
rintf(!"ello orld$ %n&)'
ddo
-
7/26/2019 L2a Hello World
10/12
errors
errors
Edit and
sav program
Compil program
Ex cut program and
valuat r sults
ddo
-
7/26/2019 L2a Hello World
11/12
The synta- rulesof a language define how we canput together symbols0 reser"ed words0 andidentifiers to make a "alid program
The semanticsof a program statement define whatthat statement means its purpose or role in aprogram!
# program that is syntactically correct is notnecessarily logically semantically! correct
# program will always do what we tell it to do0 notwhat we meant to tell it to do
ddo
-
7/26/2019 L2a Hello World
12/12
1nd
ddo