emmm, this is taken from the exam I just finished this morning:
Which one is correct:
My choice is A.
But if you take a look at potion B, it says:
"allocate 100 times of the memory size for a pointer to double and then cast the void pointer to be of type double, finally assign it to a pointer to double called ptr."
I guess B is also correct on syntax, though not as that meaningful as A.
What's your opinion?
To prove this, here is my code fragment:
It was compiled successfully and generated the correct output...
BTW I found many funny questions in exam, such as this one:
Which one is NOT a reserved word in c?
A) int
B) for
C) sizeof
D) exit
Which one is correct:
Code:
A) double *ptr = (double *) malloc(100 * sizeof(double)); B) double *ptr = (double *) malloc(100 * sizeof(double *)); C) double ptr = (double) malloc(100 * size0f(double)); D) double *ptr = (double) malloc(100*sizeof(double));
But if you take a look at potion B, it says:
"allocate 100 times of the memory size for a pointer to double and then cast the void pointer to be of type double, finally assign it to a pointer to double called ptr."
I guess B is also correct on syntax, though not as that meaningful as A.
What's your opinion?
To prove this, here is my code fragment:
Code:
#include <stdio.h> #include <stdlib.h> int main() { double *ptr = (double *) malloc(100*sizeof(double *)); printf("Hello there!\n"); return 0; }
BTW I found many funny questions in exam, such as this one:
Which one is NOT a reserved word in c?
A) int
B) for
C) sizeof
D) exit
Comment