引用它是我们声明的变量的替代名称。
可以通过传值方式访问。
它不能保存空值。
语法datatype *variablename
例如,int *a; //a包含int类型变量的地址。
指针它存储变量的地址。
我们可以使用指针来保存空值。
可以通过引用传递来访问它。
在声明变量时不需要初始化。
语法pointer variable= & another variable;
example 实例演示
#include<stdio.h>int main(){ int a=2,b=4; int *p; printf("add of a=%d
",&a); printf("add of b=%d
",&b); p=&a; // p points to variable a printf("a value is =%d
",a); // prints a value printf("*p value is =%d
",*p); //prints a value printf("p value is =%d
",p); //prints the address of a p=&b; //p points to variable b printf("b value is =%d
",b); // prints b value printf("*p value is =%d
",*p); //prints b value printf("p value is =%d
",p); //prints add of b}
输出add of a=-748899512add of b=-748899508a value is =2*p value is =2p value is =-748899512b value is =4*p value is =4p value is =-748899508
以上就是解释一下c语言中的引用和指针?的详细内容。
