what is pointer in c code example
Example 1: how to make pointers in c
datatype *var;
variable var actually holds the address of the data(memory where it is stored)
*var lets you access the data stored at that address
Example 2: poiner in c
int* pc, c, d;
c = 5;
d = -15;
pc = &c; printf("%d", *pc);
pc = &d; printf("%d", *pc);
Example 3: poiner in c
int c, *pc;
pc = c;
*pc = &c;
pc = &c;
*pc = c;
Example 4: c function pointer
int (*f_ptr)(int);
f_ptr = foo;
int r = f_ptr(v);
f_ptr = &foo;
int r = (*f_ptr)(v);
Example 5: poiner in c
#include <stdio.h>
int main()
{
int var =10;
int *p;
p= &var;
printf ( "Address of var is: %p", &var);
printf ( "\nAddress of var is: %p", p);
printf ( "\nValue of var is: %d", var);
printf ( "\nValue of var is: %d", *p);
printf ( "\nValue of var is: %d", *( &var));
printf( "\nValue of pointer p is: %p", p);
printf ( "\nAddress of pointer p is: %p", &p);
return 0;
}
Example 6: How to use pointers in C
myvar = 25;
foo = &myvar;
bar = myvar;