
问题
使用示例解释C编程语言中引用和指针的概念。
引用
它是我们声明的变量的替代名称。
可以通过传值方式访问。
-
它不能保存空值。
立即学习“C语言免费学习笔记(深入)”;
语法
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</p><p>",&a);
printf("add of b=%d</p><p>",&b);
p=&a; // p points to variable a
printf("a value is =%d</p><p>",a); // prints a value
printf("*p value is =%d</p><p>",*p); //prints a value
printf("p value is =%d</p><p>",p); //prints the address of a
p=&b; //p points to variable b
printf("b value is =%d</p><p>",b); // prints b value
printf("*p value is =%d</p><p>",*p); //prints b value
printf("p value is =%d</p><p>",p); //prints add of b
}输出
add of a=-748899512 add of b=-748899508 a value is =2 *p value is =2 p value is =-748899512 b value is =4 *p value is =4 p value is =-748899508











