CPNM Lecture 11 Pointers
CPNM Lecture 11 Pointers
Jadavpur University
2023
int *p;
int i, j, a[10], b[20], *p, *q;
char *p;
float *q;
int x=99;
int *p1, *p2;
p1=&x;
p2=p1;
printf("%p, %p %d %d\n", p1, p2, *p1, *p2);
int *f(void){
int i;
...
return &i;
}
#define ROWS 5
#define COLS 8
int **b, i, j;
b=(int **)malloc(ROWS*sizeof(int *));
p=&a[2];
q=&a[4];
printf("%d %d", *(p+2), *q);
printf("%d", p-q);
int a[ROWS][COLS];
int *p;
for(p = &a[0][0]; p<=&a[ROWS-1][COLS-1]; p++ )
*p = 0;
Assign the address of the right sort of function just by using its name
(*func)(1);
/* or */
func(1);
Example
#include <stdio.h>
#include <stdlib.h>
void func(int);
main(){
void (*fp)(int);
fp = func;
(*fp)(1);
fp(2);
}
void func(int arg){
printf("%d\n", arg);
}
fparr[2](1, 3.4);