Lecture 2 Flashcards
(6 cards)
Basic Rules 1:
Computers are very strict about punctuation & brackets:
~ every statement needs to end with a semicolon ;
~ every open parenthesis ( must be close with a closed parenthesis )
~ every open curly braces { must be closed with a close curly braces }
~ every open quote “ must be matched with a close quote “
~ every open square bracket [ must be closed with a close square bracket ]
Hello World
include
main () {
printf (“Hello World \n”);
printf (“Bye World \n”);
}
Basic Rule 2:
~ the |main| function is the start of our program, analogous to start of a letter
~ main () {} is how we define a function
• function name: main
• argument list: () - there are no arguments expected for the main function
• function definition: {} - what the function does is defined in the curly brackets
~ standard input/output library to gain more functionality
• #include
~ \n tells the computer to output a newline
Basic Rule 3:
~ you can add comments to your code to explain what you are trying to do in your code:
• single line comments:
~ // everything after the 2 slashes is ignored
• multi line comments:
~ /* this comment can end on a different line */
Compile and Execute:
Compiling: ~ it translate your C code into assembly code, object code, & then finally machine code ~ |gcc| command is doing the pre processing, compiling, assembling, and linking for you Ex: ~ gcc hello_world.c -o hello_world Executing: ~ running the executable file Ex: ~ ./helloworld
What is printf?
~ A function that outputs text
~ You get access to printf when you include the |stdio.h| library*