Answers for "basic pointer program in c"

1

pointer in c

#include <stdio.h>

int main()
{
    int j;
    int i;
    int *p; // declare pointer

    i = 7;
    p = &i; // The pointer now holds the address of i
    j = *p;

    printf("i = %d n", i);  // value of i
    printf("j = %d n", j);  // value of j
    printf("*p = %d n", p); // the address held by the pointer

    *p = 32; // asigns value to i via the pointer

    printf("i = %d n", i);   // value of i
    printf("j = %d n", j);   // value of j
    printf("*p = %d n", p);  // the address held by the pointer
    printf("&i = %d n", &i); // address of i
  
  	return 0;
    }
Posted by: Guest on February-13-2022
0

function pointer in c

// Basic syntax
ret_type (*fun_ptr)(arg_type1, arg_type2,..., arg_typen);

// Example
void fun(int a)
{
    printf("Value of a is %dn", a);
}

// fun_ptr is a pointer to function fun() 
void (*fun_ptr)(int) = &fun;
Posted by: Guest on February-06-2022

Browse Popular Code Answers by Language