Answers for "how do pointers work in c"

C
2

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
Posted by: Guest on May-02-2021
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("%u\n",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("%u\n", ptr + i);
  
    free(ptr);

    return 0;
}
Posted by: Guest on June-18-2021

Code answers related to "C"

Browse Popular Code Answers by Language