I'm an Obj-C developer who's starting to pick up ANSI C, and I've been wondering how to give a pointer a value to point to following a call to malloc. In Obj-C, all variables are initialized at some point, like this:
As I understand, this is functionally equivalent to doing something like this in ANSI C:
I tried running the following ANSI C code, and the program outputted 6:
Code:
NSObject *obj = [[NSObject alloc] init]
As I understand, this is functionally equivalent to doing something like this in ANSI C:
Code:
NSObject *obj = malloc(sizeof(NSObject));
*obj = // some value
I tried running the following ANSI C code, and the program outputted 6:
Code:
int main(int argc, const char * argv[]) {
int *p = malloc(sizeof(int));
*p = 6;
printf("%d/n",*p);
return 0;
}