COP 3014 Final Exam Questions and
Answers
What operator returns the memory address of the variable? - Answer-address operator
(&)
char = 1 byte
int = 4 bytes
doubles = 8 bytes
int x = 25;
cout << &x << end; //outputs 0x8f05
How are array names used as pointers? - Answer-array names are pointers, to the first
element in the array
What are local and global variables? - Answer-Global variables are defined outside of
the main
local variables are defined in functions
What statement causes a function to end? - Answer-return 0;
What does a pointer store? - Answer-memory addresses
What is the difference in statements:
cout << ptr << endl;
cout << *ptr << endl; - Answer-ptr prints address
*ptr prints value (dereferenced)
How do ++ and -- affect pointers? - Answer-add or subtract bytes
char = 1 byte
int = 4 bytes
doubles = 8 bytes
What operations can be used on pointers? - Answer-arithmetic operations
How do you dynamically allocate memory? - Answer-use the new function
How do you declare pointers and allocate memory to them? - Answer-int *iptr = nullptr;
iptr = new int; //requests computer to allocate enough memory for a new int variable.
, iptr contains the address of the newly allocated memory
use *iptr to assign values to dynamically allocated space
What is the null termination character for character strings? - Answer-\0
Pass parameters by reference vs by value? - Answer-reference (ref) changes value
value is a copy
Type of data returned from functions? - Answer-based on void, int, or double function
declaration
How many characters can be stored in the array: char array[1000]? - Answer-999,
because of null character \0
How do you define character arrays? - Answer-char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'}
=
char greeting[] = "Hello";
What do isupper and toupper do? - Answer-isupper checks if character is uppercase
letter
toupper converts lowercase letter to uppercase
How to declare a 2D array? - Answer-char myarray[1000] [1000];
Pass as parameter in prototype:
void checkarray(int a[ ][4]);
What do atoi and itoa do? - Answer-atoi converts string to integer
itoa converts integer to string (non-standard function)
How do you calculate the size of a character array? - Answer-Add 1 to array size to
include null character \0
How do you declare a file pointer? - Answer->> outputs to
<< receives from
How do you open a file? - Answer-ifstream datafile ("input.txt");
or
ifstream datafile;
datafile.open(filename);
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller lectknancy. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $10.49. You're not tied to anything after your purchase.