pointers c code example
Example 1: poiner in c
#include <stdio.h>
int main() {
int c = 5;
int *p = &c;
printf("%d", *p);
return 0;
}
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: 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 4: poiner in c
int c, *pc;
pc = c;
*pc = &c;
pc = &c;
*pc = c;
Example 5: how do pointers work in c programmwiz
#include <stdio.h>
int main()
{
int* pc, c;
c = 22;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c);
pc = &c;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc);
c = 11;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc);
*pc = 2;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c);
return 0;
}
Example 6: c function pointer
int (*f_ptr)(int);
f_ptr = foo;
int r = f_ptr(v);
f_ptr = &foo;
int r = (*f_ptr)(v);