3 Questions in Quiz 3 | Data Structures | CS 225, Quizzes of Data Structures and Algorithms

Material Type: Quiz; Class: Data Structures; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Unknown 1989;

Typology: Quizzes

Pre 2010

Uploaded on 03/10/2009

koofers-user-i8y-1
koofers-user-i8y-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS225 Headbangers
, #3
NetId:
1. Consider this program:
#include <iostream>
using namespace std;
template <class a, int b> void func() {
cout << "this is func";
}
int main() {
long c = 5;
func<int, c> ();
}
(a) It will not compile because cis not an int.
(b) It will not compile because cis not a constant.
(c) It will not compile since main() doesn’t return an integer.
(d) It will compile and print this is func on the screen.
2. What is true about the following code:
#include <iostream>
using namespace std;
template <int b> void func() {
cout << "foo";
}
template <long d> void func() {
cout << "bar";
}
int main() {
const long c = 5;
func<c> ();
}
(a) It will not compile since two instances of func() have conflicting signatures.
(b) It will not compile since cis a constant.
(c) It will compile and print foo on the screen.
(d) It will compile and print bar on the screen.
3. Consider the following snippet of code:
1: int x = 5;
2: int * const y = &x;
3: int const * z = &x;
4: const int * t = &x;
5: *y = 6;
6: *z = 10;
7: *t = 11;
1
pf2

Partial preview of the text

Download 3 Questions in Quiz 3 | Data Structures | CS 225 and more Quizzes Data Structures and Algorithms in PDF only on Docsity!

CS225 Headbangers ,

NetId:

  1. Consider this program:

#include using namespace std;

template <class a, int b> void func() { cout << "this is func"; }

int main() { long c = 5; func<int, c> (); }

(a) It will not compile because c is not an int. (b) It will not compile because c is not a constant. (c) It will not compile since main() doesn’t return an integer. (d) It will compile and print “this is func” on the screen.

  1. What is true about the following code:

#include using namespace std;

template void func() { cout << "foo"; }

template void func() { cout << "bar"; }

int main() { const long c = 5; func (); }

(a) It will not compile since two instances of func() have conflicting signatures. (b) It will not compile since c is a constant. (c) It will compile and print “foo” on the screen. (d) It will compile and print “bar” on the screen.

  1. Consider the following snippet of code:

1: int x = 5; 2: int * const y = &x; 3: int const * z = &x; 4: const int * t = &x;

5: *y = 6; 6: *z = 10; 7: *t = 11;

(a) It has compile error in lines 5 and 6.

(b) It has compile error in lines 6 and 7.

(c) It has compile error in lines 5, 6 and 7.

(d) There is no compile error.