The pointer in c language is a variable which can be store the address of another variable.
int n=10;
int *p=&n;
Table of Contents
Declaration a pointer in embedded
might you also like : call by value in embedded c
The pointer in c language can be declared using askterisk symbol i.e. *
int *a; //pointer to int
char *c; //pointer to char
Sample c program to explain pointer concept
#include<stdio.h>
int main()
{
int a=5;
int *b;
b=&a;
printf("%d\n%d",a,b);
return 0;
}
output:
/tmp/qRO9FB17ZJ.o
5
495777916
Explanation: In the above example we use pointer concept . Here we take two integer variable a & b. a with 5 int value and at that time declared the pointer int *b and assigned the address of a using &a. It’s appear following output
Declaration of pointer in embedded c
- Pointer to array
int arr[20];
int *p[20]=&arr;
2. pointer to a function
void show(int);
void (*p)(int)=&display;
3. pointer to structure
struct st{
int i;
float f;
}ref;
struct st*p=&ref;
Advantages of pointer in embedded c
- Using the help of pointer we reduce the complexity of code and increase the preformance.
- We can return multiple value from a function using pointer
- using pointer we able to access any memory location from computer memory.
Summary:
In this article we saw basics of pointer in embedded c
might you also like: call by reference in embedded c