# Variables

UP

(C) Theodore Norvell 1999

## Question 0

What is the result of this function

int foo(int j) {
int x = 5 ;
if( j == 0 ) {
int x ;
x = 3 ; }
return x ;
}

## Question 1

What value is returned from a call to subroutine f?

int fred = 0;
void g(int fred) {
fred = 13 ;
}
int f() {
int fred = 42 ;
g( fred ) ;
return fred ;
}

## Question 2

What value is returned from a call to subroutine f?

int fred = 0;
void g(int &frieda) { // This line is different from last time.
frieda = 13 ;     // So is this one
}
int f() {
int fred = 42 ;
g( fred ) ;
return fred ;
}

## Question 3

What values are printed by this program?

#include <iostream>
using namespace std ;

int nutsy(bool flag) {
int fred ;
if( flag ) fred = 42 ;
return fred ; }

int main() {
cout << nutsy( true ) << endl ;
cout << nutsy( false ) << endl ; }

## Question 4

What is printed by this program

#include <iostream>
#include <new>
using namespace std ;

int main() {
int *p = new(nothrow) int ;
if( p!=0 ) {
*p = 99 ;
int *q = p ;
delete q ;
cout << *p << endl ; }
}

## Question 5

What is printed by this program

#include <iostream>
#include <new>
using namespace std ;

int main() {
int *p = new(nothrow) int ;
if( p!=0 ) {
delete p ;
*p = 99 ;
cout << 12 << endl ; }
}

UP