Lecture 1 Flashcards

C programming basics

1
Q

\n

A

newline

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

include <stdio.h></stdio.h>

int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what does #include <stdio.h> mean?</stdio.h>

A

it adds the standard input/output functionality to program (header file)

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

include <stdio.h></stdio.h>

int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what is int argc?

A

integer argument for main( )

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

include <stdio.h></stdio.h>

int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what is char** argv?

A

char pointer (string array) argument for main( )

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

include <stdio.h></stdio.h>

int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what does \n mean?

A

new line

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

include <stdio.h></stdio.h>

int main (int argc, char** argv) {
printf(“Hello World!\n”);
return 0;
}
what does return 0 mean?

A

returns 0 when main is done executing, 0 here means the program ran and executed normally

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

what does GCC stand for?

A

GNU Compiler Collection

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

What is gcc?

A

software program/compiler
ex) you use gcc file.c -o file to compile program in terminal

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

gcc first.c -o first
what does -o first make?

A

executable object file named “first”

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

printf(“%s\n”, “Hello World”);

what does the input/output do here with the format specifier and string?

A

it puts “Hello World” into %s to satisfy the string format specifier, goes to standard out then prints “Hello World”

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

how to declare a variable?

A

data type variable name;

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

how to declare a variable with initialization?

A

data type variable name = value;

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

should you initialize or not initialize when declaring a variable?

A

initialize, the value assigned if you don’t initialize will not be 0 every time –> it will be assigned to whatever is left in memory

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

what are the name restrictions for variables?

A

reserved words (for, malloc, etc), cannot exceed 31 characters
cannot start with a digit

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

what is allowed for the names of variables?

A

can contain letters, digits, and underscores
ex) _brent

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

is case significant with naming variables?

A

yes, the variable Molly and molly are not the same

17
Q

arithmetic operations

A

+, -, *, /, %, ++, –

18
Q

relational operations

A

==, !=, >, <, >=, <=

19
Q

logical operations

20
Q

bitwise operations

A

&, |, ^, ~, «,&raquo_space;

21
Q

int main (int argc, char** argv) {
int d = 0;
scanf(“%d\n”, d);
printf(“d = %d\n”, d);
return 0;
}
what does scanf( ) do?

A

scanf( ) reads characters from terminal, its the keyboard (stdin)
- waits for user at that point in the program to type value in the terminal and hit return (same as scanner in java)
**input

22
Q

int main (int argc, char** argv) {
int d = 0;
scanf(“%d\n”, d);
printf(“d = %d\n”, d);
return 0;
}
what does printf(“d = %d\n”, d) do?

A

printf( ) displays the output to the screen,
for “d” –> takes whatever int is available and puts into the format specifier (“%d”)
**output

23
Q

what is a library function that writes things to to the console?

A

printf()
*output

24
Q

what is a library function that gets input/reads what the user puts in the terminal?

A

scanf()
*input

25
order of precedence
1) parenthesis 2) multiplication, division, modulus 3) addition, subtraction
26
what if there are multiple operations that have the same precedence?
operate left to right
27
post fix
a++ use a in the expression then increment
28
pre fix
++a increment a then use in expression
29
basic for loop syntax
for (int i = 0; boolean_expression; increment) { } ex) for (int i = 0; i < 3; i++) { ... }
30
basic while loop syntax
while (boolean_expression) { //executes if boolean_expression is true }
31
basic do loop syntax
do { //execute if boolean_expression is true //if false, never executes while loop } while (boolean_expression) { //if the boolean_expression^ is true, loops back through starting at do }
32
is it better to nest or not nest for looping statements?
don't nest, use compound statements instead
33
basic branching statement syntax (if and else)
if (boolean_expression) { //code here executes if boolean_expression is true } else { //code here executes if boolean_expression is false }
34
basic branching statement syntax (if, else if, else)
if (boolean_expression) { //code here executes if boolean_expression is true } else if (boolean_expression2) { //code here executes if boolean_expression is false and boolean_expression2 is true } else { //code here executes if none of the above are true }
35
is it better to nest or not nest for branching statements?
don't nest, better to use compound statements
36
1 byte =
8 bits
37
what is malloc equivalent to in java?
new both allocate space in memory for "new variable"