Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
185 Cards in this Set
- Front
- Back
What's the format descriptor for an integer? |
%d |
|
What's the format descriptor for a double? |
%lf |
|
What's the format descriptor for a character string? |
%s |
|
What does "\n" mean? |
Creates a carriage return or new line. |
|
What function reads from the keyboard/command line? |
scanf |
|
What is used to address variables, but not character strings? |
& |
|
How do you declare an input file? |
FILE *infile; |
|
Open files with: |
fopen |
|
Allow the computer to read a file with: |
"r" |
|
Allow the computer to write into an output file with: |
"w" |
|
Function that writes to an output file: |
fprintf |
|
Function that reads from a file: |
fscanf |
|
Function that closes a file: |
fclose |
|
What kind of loop repeats something a fixed number of times? |
for loop |
|
What variable type should you use as a counter? |
integer |
|
What kind of loops keeps repeating as long as a statement is true? |
while and do loops |
|
When do "while" loops check to see if the loop should be executed (again)? |
Before starting |
|
When do "do" loops check to see if it is executed (again)? |
After the first pass/ At the end |
|
What include header defines variable types? |
#include <stdio.h> |
|
Statement that only does something is a given statement is true. |
if statement |
|
Picks between two options depending on whether a given statement is true or false. |
if/else statement |
|
Chooses based on the first true expression the computer finds. |
if/else if/else statement |
|
Chooses between several options based on the value of an integer or character. |
switch statement |
|
Function that every code must have: |
main() |
|
How many values do functions return? |
one |
|
Functions take ________: |
arguments |
|
Functions have syntax defined by these type of statements: |
prototype |
|
These allow direct access to memory locations where variables are stored in 1's and 0's: |
pointers |
|
Address pointers via: |
& |
|
Give content to pointers via: |
* |
|
In function prototypes use these as arguments to pass pointers into functions: |
pointer-to-values |
|
Call with these as arguments when passing pointers to functions when calling the function: |
pointer-to-address |
|
In the function definition use these as arguments when passing pointers into functions: |
pointer-to-values |
|
What is an operating system? |
Software that supports computer basic functions. Manages hardware and software resources and common services for computer programs (i.e.memory processes). Allows you to speak the computers language. |
|
What are the main hardware parts of a computer? (There are six) |
Central Processing Unit (CPU), Northbridge/Southbridge, Memory, Hard drive/disk, Input devices, Graphics card |
|
What is a compiler? |
Translates human-readable code into low-level instructions for the CPU. |
|
Lists files in the directory |
ls |
|
Lists files in the directory with sizes shown |
ls -l or ls -al |
|
Renames the files |
mv |
|
Moves the files into a subdirectory |
mv file.cpp sub |
|
Define an integer variable i: |
int i; |
|
Define a floating point variable with value 3.14 which can't change: |
const double PI=3.14; |
|
Statement to read a double value from the command line into a variable named discount: |
scanf("%lf", &discount); |
|
Print double variable q in scientific or floating point notation, whatever's more compact: |
printf("%g", q); |
|
Using file pointer, input_file, open the file results.dat for read mode: |
input_file = fopen("results.dat", "r"); |
|
Reads an integer from the program's command line: |
int i = atoi(argv[1]); |
|
Function pointer type that can point to sqrt() function in the C math library: |
double (*f)(double x) |
|
All C functions must contain: |
main() |
|
Correct operator to compare two numerical values: |
== |
|
How man times is a "do while" loop guaranteed to loop? |
1 |
|
What is a parent distribution? |
Represents the probability of observing a particular value w/ infinite points (i.e. in a perfect world). |
|
What is a sample distribution? |
Experiments draw measurements at random from the parent distribution. Creates a histogram. |
|
Role of the Gaussian distribution in measurements? |
Measures of random processes, in the limit of many samples, often tend to produce a characteristic Gaussian/Normal distribution. |
|
What's the Central Limit Theorem? |
Sufficiently large numbers of randomly distributed measurements will always approach a Gaussian distribution. |
|
What's a systematical uncertainty? |
Features of the measurement device or technique that shift the measured result to the true value. |
|
What's a statistical/random uncertainty? |
Features of the measurement device or technique that shift the measured result by a different amount in each attempt (random). |
|
What's a CPU do? |
Does the actual computer work. (i.e. the brain) |
|
What's a Northbridge/Southbridge? |
Middlemen that handle fast and slow input/output and inter-component communications. |
|
What's Memory? |
Temporary storage of data needed rapidly when running programs. |
|
What's a Hard drive/disk? |
Permanent, long-term storage of data. |
|
What's Input: |
Enables interaction w/ users. |
|
What's a graphics card? |
Middlemen that allow for visual output to be displayed. |
|
What's the capacity/access of a disk? |
Large capacity, slow access. |
|
What's the capacity/access of memory? |
Reasonable capacity, fast access. |
|
What's the capacity/access of cache? |
Meager capacity, really fast access. |
|
Narrows results using this on the command line. |
* |
|
What's a shell? |
Intermediates between the user and the operating system. |
|
Memory allocation for a character: |
1 byte |
|
Memory allocation for an integer: |
4 bytes |
|
Memory allocation for a float: |
4 bytes |
|
Memory allocation for a double: |
8 bytes |
|
Who is Dennis Ritchie? |
Defined the relatively simple syntax of C as part of the Unix R&D. Wrote the first compiler for C programs. |
|
The body of a function is delimited by: |
braces |
|
Used to indicated comments: |
// blah or /* blah */ |
|
Functions such as printf and scanf are included in which header? |
#include <stdio.h> |
|
Data is stored in ____: |
bits |
|
One value is called a _____: |
bit |
|
Bits are grouped together in groups of _____: |
eight |
|
8 bits equals a _____: |
byte |
|
Why are 8 bits a convenient grouping? |
They use binary arithmetic (of 1's and 0's) |
|
Declares a "small" integer type: |
short int |
|
Declares a "medium" integer type: |
int |
|
Declares a "large" in integer type: |
long int |
|
What's a float? |
A real (floating point) number. |
|
What's a double? |
A "double precision" floating point number. |
|
What's a long double? |
Even higher precision than a double. |
|
What's char? |
Declares a character of text. |
|
What's a "string" of characters equivalent to? |
An array of single chars. |
|
When should variables be defined in the function they are being used? |
At the beginning |
|
What if you do not initialize a defined variable? |
C doesn't initialize variables and it will reuse memory space when defining a new variable. |
|
What's the benefit of using preprocessor definitions? |
Can speed up your program at run time since fewer vars are stored in memory, meaning few accesses. |
|
Why is using const better than defining a variable? |
The compiler won't let it be altered when the code runs. |
|
The "sizeof" statement is used to find out what? |
The number of bytes used by a variable or data type. |
|
Implicit casting is bad because? |
Data isn't managed by the programmer and it this downward cast would truncate the value of the variable making it have lower precision. |
|
How do you cast float variable a into an int i? |
i = (int) a; |
|
What format specifier uses either scientific notation or regular notation, whichever is shorter? |
%g |
|
What are format specifiers? |
They translate the internal representation of the data into the text on your screen. |
|
Makes a new page: |
\f |
|
Moves you back a character: |
\b |
|
Goes to the beginning of the line |
\r |
|
Goes to the next tab stop: |
\t |
|
Rings a bell: |
\a |
|
Prints the character \: |
\\ |
|
Prints the character " : |
\" |
|
What does binary operator gives you a remainder? |
% |
|
Logical inequality |
!= |
|
Logical NOT. Invert a test or true/false : |
! |
|
Logical AND |
&& |
|
Logical OR |
|| |
|
Any measurable value has a ____ value: |
true |
|
Why do we see a range of measured values? |
Imperfections and limitations in our instruments and measurements. |
|
Define mean: |
average value of the distributions |
|
Define variance: |
characterizes the width of the data |
|
Define standard deviation: |
Tells us about the distribution of our values. Is the square root of the variance. |
|
What matters more, the number of measurements you make or the number of points thrown? |
NEITHER MATTERS. What matters is just the total number of points in all measurements combined. |
|
Each statement must end with a: |
semicolon (;) |
|
Who wrote the g++ compiler? |
Richard Stallman |
|
In the following what is myprogram? g++ -o myprogram myprogram.cpp |
An output file which is an executable binary file. You run the program by typing myprogram into the command line. |
|
Two ways to write an "if" statement: |
if(CONDITION){ BLOCK of statements }
or
if(CONDITION) statement; |
|
If a condition is zero then it is: |
false |
|
If a condition is not zero then it is: |
true |
|
Why can't you use == for floating point numbers? |
There is limited precision of the calculations. |
|
What should one use instead of == for comparing floating point values? |
Use inequalities to see if the difference between the floating point numbers is less than some threshold. |
|
What does the fabs() function do? |
Returns the absolute value of a floating point number. |
|
What does "break" mean in a switch statement? |
Jumps out of the switch statement and continues with the rest of the program. |
|
What happens if you omit a break in a switch statement? |
The program will continue to work its way through the switch statement, possibly matching other cases. |
|
How do you use a "?" operator? |
CONDITION ? ( true) STATEMENT : (false) STATEMENT; |
|
What are count-controlled loops? |
Used when the user knows beforehand how many times they want to repeat a series of tasks. |
|
What are condition-controlled loops? |
Are used when the user doesn't know how many repetitions will be needed, but that they want to stop when some well-defined thing happens. |
|
What are loops? |
Execute repetitive boring tasks efficiently and accurately over and over. |
|
What are the four important parts for a for() loop? |
Counter initialization, test condition, counter update, and body of execution. |
|
What does a "continue" statement do? |
Skips the rest of the current loop and goes directly to the next iteration. |
|
What's the syntax for a "do" loop? |
do { BLOCK of statements } while (CONDITION); |
|
What does it mean to "nest" loops? |
Place one loop inside of another. |
|
What is a variable's scope? |
Refers to where a variable can be accessed. |
|
Define local scope. |
Variables defined inside a function that are available only in that function |
|
Define global scope. |
Variables that are defined outsides all functions and accessed anywhere. |
|
What happens if a variable named is used twice once inside of a function and once globally? |
The local variable will override the global definition, but only within that function. The global variable is unaffected. |
|
What type of scope should you limit your variables to? |
The smallest scope possible. |
|
What's bad with having multiple globally defined variables? |
They can be manipulated/changed ANYWHERE in your code. It will still run, but it can lead to confusion. |
|
What is a pass-by-value function? |
The initial values of arguments are not allowed to change globally. They can change interior to the function, but those changes are never carried out on the global variable. Copies of the input variables are made but not used beyond the function. |
|
What is a pass-by-reference function? |
Arguments can be values or memory locations. Output can be "returned" through the parameter list. Allows multiples results to be accessible to the rest of program. |
|
Format specifier used to print memory addresses: |
printf(" %p", &variable); |
|
What is a pointer? |
A special kind of variable that holds the memory address of another variable. |
|
What happens if you don't put an & when scanning in numbers? |
scanf wouldn't know the addresses of these variables and it wouldn't be able to modify their contents. |
|
What's the advantage of passing pointers as arguments to functions? |
The user can manipulate an arbitrary number of variables, rather than just return one result. |
|
What does a segmentation fault error mean? |
The computer is trying to access or write in a part of the low lying memory that belongs to the operating system which user made programs don't have permission to. |
|
What are static variables? |
Static variables declared in function blocks are preserved between function calls. They are created at program start up and defined for the duration of the program. |
|
What are recursive functions? |
They are functions that are defined in terms of themselves. |
|
All recursive functions must have this condition so that the recursion has a limit: |
terminating condition |
|
How would you define a double vector <1,2,3> as an array? |
double vector[3] = {1.0,2.0,3.0}; |
|
What are an arrays indicies? |
Zero to N-1 (where N is the size of the array) |
|
How do types work with array? |
The elements of an array can be any type but all elements of an array must be the same time. |
|
When defining an array where do you place the the number of elements within the array? |
inside the square brackets |
|
What type must an array index be? |
An integer |
|
What is the most common source of run-time errors when using arrays? |
C doesn't check your array indices to make sure they're within the array. |
|
When passing an array to a function do you specify the size in the square brackets? |
NO |
|
When passing an array to a function how do you specify the size? |
Declare a function: void print_stuff (float a[], int size);
Inside the main: int max = 20; float an_array[max]; print_stuff(an_array, max); |
|
How do you make a 2D array? |
Specify two indices. ex: double matrix[nrow][ncol]; |
|
What is a consequence of defining an array of any size? |
The footprint of that array's size is dedicated in the computer's memory. Can easily exhaust a computer's memory by defining arrays that are too large. |
|
What is an array of characters? |
A string |
|
An array is equivalent to a _____: |
pointer |
|
Why don't we need to put an & in front of names of character strings? |
These variables are already pointers. |
|
How do you set up your condition for int main() so that it can take arguments from the command line? |
int main( int argc, char *argv[ ]) |
|
What is argc? |
Is the "argument count", the number of arguments the operating system is giving us. |
|
What is argv? |
Is the "argument vector", which is an array of character strings. |
|
All arguments are read into memory as: |
text strings |
|
Text strings can be accessed via: |
argv |
|
What is the first arguments when making an array from the command line? |
The program name. Has index zero (first index). |
|
Converts text to an integer: |
atoi |
|
Converts text to a double: |
atof |
|
Converts text to a long: |
atol |
|
Converts text to a float: |
atoff |
|
When defining header files angle brackets (<>) are reserved for what type? |
Reserved for files in the "standard" system directories. |
|
How do you include a code you wrote called, oldcode.cpp ? |
#include "oldcode.cpp" |
|
What's a drawback of include your old code? |
The computer has to compile the extra code as well. |
|
What is an object file? |
It is compiled code that hasn't been fully processed into a program. |
|
Make (compile) an object file for sqrtn.cpp |
g++ -O -Wall -c sqrtn.cpp |
|
If you compile a code into an object file what is the output? |
file.o |
|
If you have a precompiled object file how would you include that into a code? |
#include "file.hpp" |
|
What do function pointers allow you to do? |
Allow you to pass functionality around your program like data. |
|
What is the bolded part of the following:
double (*f) (double x) |
The pointer points to a function that return a "double". |
|
What is the bolded part of the following:
double (*f) (double x) |
The name of the function pointer is "f". The name must be enclosed in parentheses. |
|
What is the bolded part of the following:
double (*f) (double x) |
This pointer points to a function that takes one argument, of type "double". |
|
What format specifier only print in scientific notation? |
%e |