rgb192
asked on
pointer typecasting
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;
int aj;
int aj2;
int bj;
printf("Enter size of array\n");
scanf_s("%d", &n);
int *A = (int*)malloc(n*sizeof(int));//dynamically allocated array
for (int j = 0; j < n; j++)
{
aj2 = j + 1;
A[j] = j + 1;
aj = A[j];
}
//free(A);
//A[1] = 3; //value at address A+1;
int *B = (int*)realloc(NULL, n*sizeof(int)); //equivalent to malloc
printf("Prev block address=%d, new address=%d difference=%d\n", A, B,(B-A));
for (int j = 0; j < n; j++)
{
bj = B[j];
printf("%d ", B[j]);
}
}
I am doing self study, copying code from tutorial.
int *B = (int*)realloc(NULL, n*sizeof(int)); //equivalent to malloc
I do not undertand (int*) typcasting
would (int) force a number where there is a decimal
4.01=4
I do not undertand (int*)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.