1730 - Midterm Deck Flashcards
What is a program
a program is a set of instructions for a computer
What is an algorithm
an algorithm is a step-by-step approach to solving a problem
what kind of codes/languages did early computers use
machine code (binary) and assembly languages
what are some examples of high-level languages that we know
Java and C
how are higher-level languages better for us
they allow programmers to write code independent of hardware
what are some examples of operating systems
Unix, Windows, MacOS, Linux
what do operating systems do
manage computer resources and provide an interface for the users
what does a compiler do
it analyzes a program developed in a particular computer language and translates it into a form that is suitable for execution on your particular computer system
what is a syntactic error
an syntax error (like unbalanced parenthesis or brackets)
what is a semantic error
an error that occurs when special data is inserted when not defined (so like when you have an undefined variable)
compilation process
reads code line-by-line and if any error is found, it tells the programmer and ends.
if no semantic or syntactic errors are found then compiler translates code from higher lang. to lower lang. for the computer to understand
what process does the term “building” refer to
the process of compiling and linking a program
what happens after the compilation process
the compiled file is then linked to an executable file
what happens when linking
the assembler takes each assembly language and converts it into a binary format known as object code
what is the default name of an executable file in Unix
a.out
what is the difference between unsigned and signed numbers
unsigned = non-negative values, while signed includes negative values
i have a file called file1.txt on my laptop that I want to upload to odin… what would I type in?
scp file1.txt odinUsername@odin.cs.uga.edu:~/[relative path to where you want to upload it on odin]
I have a program called Connect4.c on odin that I want to download on my laptop… what would I do
- cd to where you want to save in on your device
- scp odinUdername@odin.cs.uga.edu:~/[realtive path of where the file is on odin/Connect4.c .
what are the 3 programming goals
- correctness
- readability
- optimization
difference between Java and C/C++ on compiling
Java needs a JVM, so when a program is compiled, the compiler produces a .class file that the JVM can understand.
C/C++ does not require a VM as the result of a “build” is an executable file that will run on the native operating system
what is the act of creating an executable file known as in C
linking
can you individually compile source files into object files in C like you have to in Java?
yes, you can.
what are the phases of C/C++ programs
- Edit
- Preprocess
- Compile
- Link
- Load
- Execute
T/F: Java has a preprocessor
False, and it is one of the most noticeable differences between Java and C/C++
What is the C equivalent for import java.lang.String;
include <string.h></string.h>
what are some differences between Java and C/C++ in terms of memory
in C/C++, you must manually deallocate memory using the free (C)/delete (C++) method; whereas Java has an automatic garbage collector so the programmer does not have to worry as much about memory
Are pointers more powerful in Java or C/C++?
C/C++
how many byes is a char
1 byte
how many bytes is an int
4 bytes
how many bytes is a double
8 bytes
how many bytes is a float
4 bytes
how many bytes is a long
8 bytes
how many bytes is a short
2 bytes
is C/C++ case sensitive
yes!
what is the java equivalent to a final variable
constant (ex. const char = ‘a’;)
what does &foo return
the memory address of foo
what is an array
an array is a sequence of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to the unique identifier
T/F: an array can be dynamically-sized
false, arrays have a fixed size
T/F: int a[3][5] is the same as int a[15]
true, any multidimensional array can be written as a simple array
how to pass an array as a parameter
you declare the parameter to be the array, but omit the size in the bracket
int main(int argc, int argv[ ]) { }
(when you do this, you need a variable to tell you the length of the array, which is argc in this case)
T/F: when calculating the length of an char array, the program adds 1 to the length because the computer is dumb
false; it adds 1 to the length because every char array as a ‘\0’ character at the end to null-terminate the array
2 ways to initialize a character array:
- like you would normally do for any array:
char myword[ ] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’}; - the string literal way:
char myword[ ] = “Hello”;
if we have char myword[] = “Hello”; can we do char myword[] = “Bye”
no, this won’t compile, to chance the contents of myword, the user would have to manually do so:
myword[0] = ‘B’;
myword[1] = ‘y’;
myword[2] = ‘e’;
myword[3] = ‘\0’;
what is the reference operator
&
what is the dereference operator
*(and is attached to the variable)
how to initialize a pointer
type * name
example -> int * number
what is a pointer
a variable that stores the address of another variable
how are dereference variables translated
the value pointed to by
baz = *foo; baz is the value pointed to by foo.
how are reference variables translated
& is the “address of”
foo = &myvar; foo is the address of myvar
what is int * p1, p2
p1 is a pointer and p2 is simply an int
int * p1;
int p2;
int myarray[20];
int * mypointer;
mypointer = myarray;
Why is this valid?
mypointer is assigned to the memory address at which myarray begins
what is the main difference between pointers and arrays
pointers can be assigned to new addresses, while arrays cannot
what is a[5] equal to in pointer form
*(a+5)
which has more precedence in this statement: *p++ = *q++
++ has greater precedence than *
what is *p++ = *q++ roughly equivalent to
*p = *q
++p;
++q;
what is the main reason for byte alignment
to improve memory access speed