Explain the concepts of references and pointers in C programming language using examples.
It is an alternative name for the variable we declared.
can be accessed by value.
It cannot hold null values.
datatype *variablename
For example, int *a; //a contains the address of an int type variable.
#It stores the address of the variable.
We can use pointers to save null values.
It can be accessed by passing by reference.
No initialization is required when declaring variables.
pointer variable= & another variable;
Example demonstration
#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
The above is the detailed content of Explain references and pointers in C language?. For more information, please follow other related articles on the PHP Chinese website!