Lecture 2 Flashcards

(6 cards)

0
Q

Basic Rules 1:

Computers are very strict about punctuation & brackets:

A

~ 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 ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

Hello World

A

include

main () {
printf (“Hello World \n”);
printf (“Bye World \n”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Basic Rule 2:

A

~ 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Basic Rule 3:

A

~ 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 */

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Compile and Execute:

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is printf?

A

~ A function that outputs text

~ You get access to printf when you include the |stdio.h| library*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly