

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Quiz; Class: Data Structures; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Unknown 1989;
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


NetId:
1: int main () { 2: int *x = 0; 3: int &a = *x; 4: return 0; 5: }
(a) This generates compile error in line 2. (b) This generates compile error in line 3. (c) This compiles fine, but will generate segmenation fault when executed (runtime error). (d) This compiles and executes without any system error.
#include
class Test { public: Test(int a) { p = new int; *p = a; }
~Test() { cout << *p << "\n"; delete p; p = NULL; }
private: int *p; };
What is the output of the following program:
int main() { Test t(10); t.~Test();
return 0; }
(a) No output. Generates segmentation fault. (b) Outputs 10 and then generates segmentation fault. (c) Outputs 10 in the first line and 0 in the second line. (d) Outputs 10 in the first line and 10 in the second line.
int main() { Test t(10); t.Test(20);
return 0; }
(a) This will not be compiled. (b) No output and no memory leak. (c) No output and we have memory leak. (d) Outputs 10. (e) Outputs 20 and we have memory leak.
int main() { Test *t, *tt; t = new Test(10); *tt = *t;
return 0; }
(a) This will not be compiled. (b) Generates segmentation fault with no memory leak. (c) Generates segmentation fault and memory leak. (d) Outputs 0.