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

A

&&, ||, !

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
Q

order of precedence

A

1) parenthesis
2) multiplication, division, modulus
3) addition, subtraction

26
Q

what if there are multiple operations that have the same precedence?

A

operate left to right

27
Q

post fix

A

a++
use a in the expression then increment

28
Q

pre fix

A

++a
increment a then use in expression

29
Q

basic for loop syntax

A

for (int i = 0; boolean_expression; increment) {
}
ex) for (int i = 0; i < 3; i++) {

}

30
Q

basic while loop syntax

A

while (boolean_expression) {
//executes if boolean_expression is
true
}

31
Q

basic do loop syntax

A

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
Q

is it better to nest or not nest for looping statements?

A

don’t nest, use compound statements instead

33
Q

basic branching statement syntax (if and else)

A

if (boolean_expression) {
//code here executes if
boolean_expression is true
} else {
//code here executes if
boolean_expression is false
}

34
Q

basic branching statement syntax (if, else if, else)

A

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
Q

is it better to nest or not nest for branching statements?

A

don’t nest, better to use compound statements

36
Q

1 byte =

A

8 bits

37
Q

what is malloc equivalent to in java?

A

new
both allocate space in memory for “new variable”