You are currently viewing Basics of pointer in embedded c
Basics of pointer in embedded c

Basics of pointer in embedded c

Spread the love

The pointer in c language is a variable which can be store the address of another variable.

int n=10;
int *p=&n;

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

basics of pointer in embedded c
pointer in embedded c

Declaration of pointer in embedded c

  1. 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

  1. Using the help of pointer we reduce the complexity of code and increase the preformance.
  2. We can return multiple value from a function using pointer
  3. 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

sachin Pagar

I am Mr. Sachin pagar Embedded software engineer, the founder of Sach Educational Support(Pythonslearning), a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Reply