Escolar Documentos
Profissional Documentos
Cultura Documentos
January 2018
1
Installations
2
Hello World
3
HelloWorld.c
4
Hello World
Comments
Text surrounded by /* and */ is ignored by computer
Used to describe program
#include <stdio.h>
Preprocessor directive
Tells computer to load contents of a certain file
<stdio.h> allows standard input/output operations
5
Hello World
int main()
Used to describe program
C programs contain one or more functions, exactly
one of which must be main
Parenthesis used to indicate a function
int means that main "returns" an integer value
Braces ({ and }) indicate a block
The bodies of all functions must be contained in braces
6
Hello World
printf( "Hello World\n" );
Instructs computer to perform an action
Specifically, prints the string of characters within quotes (“ ”)
Entire line called a statement
All statements must end with a semicolon (;)
Escape character (\)
Indicates that printf should do something out of the ordinary
\n is the newline character
7
Hello World
Right brace }
Indicates end of main has been reached
Linker
When a function is called, linker locates it in the library
Inserts it into object program
If function name is misspelled, the linker will
Produce an error because it will not be able to find
function in the library
8
Hello World – Further Practice
9
Hello World – Further Practice
Modify HelloWorld.c
Remove the line #include <stdio.h>
Execute->Compile
See the compilation results
What do you see?
[Error]Printf was not declared in the scope
Include the line #include <stdio.h> and compile
Is the error gone?
10
Hello World – Further Practice
Modify HelloWorld.c
Remove the semicolon character “;” in printf
printf(“Hello World\n”)
Execute->Compile
See the compilation results. What do you see?
[Error] Expected ‘;’ before ‘}’ token
Add the ; in printf and compile
Is the error gone?
11
Hello World – Further Practice
Modify HelloWorld.c
Remove one of the “ character in printf
printf(“Hello World\n);
Execute->Compile
See the compilation results. What do you see?
[Error] Missing terminating ‘”’ character
Add the ” in printf and compile
Is the error gone?
12
Thank You
13