12/15/2013

C++ Variable of reference

#include <stdio.h>

struct point{
    int x;
    int y;
};

typedef struct point Point;
int main(){
    
    Point p1;
    Point &px = p1;
    
    p1.x = 10;
    p1.y = 20;
    
    Point p2 = p1;
    
    px.x = 11111;
    px.y = 1122;
    
    printf("Point 1: %d %d", p1.x, p1.y);
    printf("Point 2: %d %d", p2.x, p2.y);
    printf("There are two distinct object: Point 1 and 2");
}

No comments:

Post a Comment