Answers for "c what is a pointer"

0

pointer c

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *ptr, i , n1, n2;
    printf("Enter size: ");
    scanf("%d", &n1);

    ptr = (int*) malloc(n1 * sizeof(int));

    printf("Addresses of previously allocated memory: ");
    for(i = 0; i < n1; ++i)
         printf("%un",ptr + i);

    printf("nEnter the new size: ");
    scanf("%d", &n2);

    // rellocating the memory
    ptr = realloc(ptr, n2 * sizeof(int));

    printf("Addresses of newly allocated memory: ");
    for(i = 0; i < n2; ++i)
         printf("%un", ptr + i);
  
    free(ptr);

    return 0;
}
Posted by: Guest on June-18-2021
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