Você está na página 1de 13

Hello World in C

January 2018

1
Installations

 You must have installed Dev C++ on your system


 You must have downloaded Exercises Folder in
your system

2
Hello World

Open Dev C++


Click File->Open->HelloWorld.c
Click Execute->Compile
 What does Compile do?
Click Execute->Run
 What does Run do?
What do you see as output?

3
HelloWorld.c

#include <stdio.h> // Header File to be included


main() // Execution starts here
{ // Block/Function start
printf("Hello World\n"); // Print a string
} // Block or function end

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

Open Dev C++


Modify HelloWorld.c
Change the string in the printf
 printf (“ Any string you choose\n”)
 Execute->Compile
 Execute->Run
What do you see as output?

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

Você também pode gostar