使用示例解释C编程语言中引用和指针的概念。
它是我们声明的变量的替代名称。
可以通过传值方式访问。
它不能保存空值。
立即学习“C语言免费学习笔记(深入)”;
datatype *variablename
例如,int *a; //a包含int类型变量的地址。
它存储变量的地址。
我们可以使用指针来保存空值。
可以通过引用传递来访问它。
在声明变量时不需要初始化。
pointer variable= & another variable;
实例演示
#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
以上就是解释一下C语言中的引用和指针?的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号