C
Chad
Give the following...
#include <stdio.h>
#include <stdlib.h>
struct point{
int x;
int y;
};
int main(void)
{
struct point *points;
if ((points = malloc(sizeof(struct point))) == NULL) {
fprintf(stderr, "unable to allocate memory\n");
exit(1);
}
free(points);
exit(0);
}
Doesn't the if statement only expressions and not expression-
statements? Just curious, because (points = malloc(sizeof(struct
point)) is an expression-statement. How does this get converted to an
expression so that the if statement can use it?
Chad
#include <stdio.h>
#include <stdlib.h>
struct point{
int x;
int y;
};
int main(void)
{
struct point *points;
if ((points = malloc(sizeof(struct point))) == NULL) {
fprintf(stderr, "unable to allocate memory\n");
exit(1);
}
free(points);
exit(0);
}
Doesn't the if statement only expressions and not expression-
statements? Just curious, because (points = malloc(sizeof(struct
point)) is an expression-statement. How does this get converted to an
expression so that the if statement can use it?
Chad