ReferenceStyle

ReferenceStyle - (&) is written next to x. */ int...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> using namespace std ; int main() { int a = 4, b = 5 ; /* The declaration int& x = a, y = b ; is visually misleading. It suggests that x and y are int references. But only x is; y is an int. It is better to use the follow declaration. The compiler will treat it exactly as the one above but this one suggests that x is an int reference and y is an int since the ampersand
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (&) is written next to x. */ int &x = a, y = b ; cout << "a=" << a << ", b=" << b << ", " << "x=" << x << ", y=" << y << endl ; a = 14 ; b = 15 ; cout << "a=" << a << ", b=" << b << ", " << "x=" << x << ", y=" << y << endl ; x = 24 ; y = 25 ; cout << "a=" << a << ", b=" << b << ", " << "x=" << x << ", y=" << y << endl ; return 0 ; }...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Ask a homework question - tutors are online