Shared Flashcard Set

Details

Exam 1
Everything
49
Computer Science
Undergraduate 1
03/03/2013

Additional Computer Science Flashcards

 


 

Cards

Term

Where is memory from compile time (static memory) stored?

 

Definition
The stack
Term
Where is memory from runtime (dynamic memory) stored?
Definition
the heap
Term
do changes to the parameters affect arguments in pass by value?
Definition
no
Term
Do changes to parameters affect the arguments in Pass by Reference?
Definition
yes
Term
How do you declare a pass by reference variable in a parameter?
Definition

use "&" between data type and variable name.

void HT(int&x)

Term
How increment "p" by "i"
Definition

p = ++i;

p = i++;

Term
ways to initialize a static array
Definition

int data[10];

int data[] = {1,2,4};

int data[10] = {1,2,4};  //assigns first three, rest are 0

int data[10] = {0};   //clears array

Term
How to pass array data of size 10 into void function doubleA
Definition

void doubleA(int[], int);

int main()

{

   int data[10];

   //ask user to enter 10 values

   doubleA(data, 10);

   return 0;

}

 

void doubleA(int d[], int size)

{

   for (int i = 0; i < size; i++)

      d[i] = d[i] * 2

}

Term
how to copy string "name" into "name2"
Definition

strcpy(name2, name);

//destination must be long enough

Term
how to determine the length of string "name" and place into variable "var" (2 ways)
Definition

int var = strlen(name);

int var = name.length();

Term
  1. how to compare the contents of string "arg1" with string "arg2"
  2. how are they compared
  3. what is returned if
  • arg1 < arg2
  • arg1 > arg2
  • arg1 == arg2  
Definition
  1. strcmp(arg1, arg2)
  2. compares each member of strings until 2 different values are reached
  3. returns:
  • <0
  • >0
  • 0

 

Term

int data[5][6];

which is columns, which is rows

Definition
int data[rows][columns];
Term
passing 2D array
Definition

main()

{

   int data[5][6];

   foo data();

}

 

void foo(int d[][6])

{} 

Term
How many bytes are grouped to make an integer?
Definition
4
Term

What does the Virtual Memory Manager (VMM) do?

What does it allow?

Definition

swaps memory between RAM and hard drive.

Allows more space than thats available on RAM to be used in a program

Term
What is stored inside of a pointer variable?
Definition
A memory address
Term
how do you declare an integer pointer "p"?
Definition
int*p;
Term

How do you initialize a 2-dimensional int array?

2-dimensional char array?

 

Definition

int data[4][3] = {{1,3,5}, {2,4,6}, {9,10,11}, {1,1,1}};

char names[5][4] = {"SMU", "TCU", "UTD", "UTA", "UN"}

// S M U ø

//null-terminated c-strings

Term
how to display a the memory address of variable x
Definition
cout<< &x;
Term
What does it mean to dereference a pointer?
Definition
To go to the address that is held in that variable and change its contents
Term
How to derefernce variable "p" and change it to 15?
Definition
*p = 15;
Term
if int y[10]; is a "constant pointer" to the memory address 2012, where does y+1 point?
Definition
2016 (second element of the array)
Term

what is another way of writing d[i]?

(subscript notation ↔ pointer offset deferenced)

Definition
*(d + i)
Term

char data[10] = "SMU";

cout << data;

 

//what will display?

Definition
SMU
Term

words[10] = "SMU"

char*data = words;

cout << *data;

 

//what will display?

Definition
SMUø
Term

char data[10] = "SMU";

cout << data+1;

 

//what will display?

Definition
MU
Term

char names[5][7] = {"SMU", "TCU", "UTD", "UNT", "UTA"};

 

cout << names[3] + 1;  //what will display?

 

Definition
NT
Term

char names[5][7] = {"SMU", "TCU", "UTD", "UNT", "UTA"};

 

cout << *names;  //what will display?

Definition
SMU
Term

char names[5][7] = {"SMU", "TCU", "UTD", "UNT", "UTA"};

 

cout << *(names[4] + 2);  //what will display?

Definition
A
Term

char names[5][7] = {"SMU", "TCU", "UTD", "UNT", "UTA"};

 

cout << *(*(names + 2) + 1);  //what will display?

Definition
T (of UTD)
Term

char names[5][7] = {"SMU", "TCU", "UTD", "UNT", "UTA"};

 

cout << (*names + 1);  //what will display?

Definition

MU

= names[0] + 1

Term
declare and initialize a dynamic integer array of size m integers, "p"
Definition
int*p = new int[m];
Term
  1. What is a memory leak?
  2. How do you avoid this?
Definition
  1. memory that is allocated but never deallocated
  2. free/deallocate any dynamically allocated memory
Term
  1. If you have allocated an array pointed to by x, how do you free this memory?
  2. For a non-array?
Definition
  1. delete[] x;
  2. delete x;
Term

What is wrong with the following?

int*p;

cout << *p;

Definition
uninitialized pointer, you may get a segmentation fault
Term
How to make an array of char pointers of length 5 called "temp"
Definition
char**temp = new char*[5]
Term
what do you need to #include for file IO?
Definition
#include <fstream>
Term
  1. input from a file
  2. output to a file
Definition
  1. ifstream
  2. ofstream
Term
how to reset a file object for looping
Definition
fin.clear();
Term
how to do end of file marker for "fin"
Definition
fin.eof()
Term
how to read an entire line to fill char data[50]
Definition

getline(destination array variable name, number of spaces);

i.e.

char data[50];

fin.getline(data, 50);

Term

How to create a file called output.txt

ofstream fout;

Definition

fout.open("output.txt");

Term
how to ignore a line in a file for "fin"
Definition

fin.ignore(amount of space, another amount of space);

i.e. fin.ignore(80, '\n');

Term
  • Between pass by reference and pass by value, which is faster?
  • Why?
Definition
  • Pass by reference
  • No copy is made
Term
What does "using namespace std" allow user access to?
Definition
components of the c++ standard library
Term
what is ">>"
Definition
the stream extraction operator
Term
what is "<<" called?
Definition
the stream insertion operator
Term

how to promote

short a = 2000;

to int b?

Definition

short a = 2000;

int b = a;

Term
what can be used as a size declarator for a static array?
Definition
a number (integer literal) or a const variable (named constant)
Supporting users have an ad free experience!