i am new to c
#include <stdlib.h>
#include <stdio.h>
int main() {
int *var = (int *) malloc(sizeof(int) * 2) ;
*var = 22;
printf("%d \n" , var);
free(var);
return 0;
}
is this the right way to assign a value to a variable created using malloc? because i've been trying to give it a value by doing
var = 22;
because when creating a 'string' in c and assigning a value to it it is done like this
char *var;
var = "birds are dying";
not like
*var= "birds are dying";