C++传指针和引用demo

来源:互联网 发布:ubuntu系统下安装win7 编辑:程序博客网 时间:2024/06/08 13:11
#include <stdio.h>#include <iostream>using namespace std;//1.传指针void trans_pointer(int *x)  {    *x = 100;}//2.传引用void trans_quote(int &x)  {  x = 200;}int main()  {    int p = 4;    trans_pointer(&p);  printf("pointer = %d \n", p);    trans_quote(p);    printf("quote = %d \n", p);    return 0;  }