WorksheetsQuiz on File, Memory Alloc, Preprocessor, Structure & Union
Total questions: 20
Worksheet time: 23mins
Can you combine the following two statements into one?
char *p;
p = (char*) malloc(100);
What will be the output?
int main()
{
struct site
{
char name[] = "BETA";
int no_of_pages = 100;
};
struct site *ptr;
printf("%d ", ptr->no_of_pages);
printf("%s", ptr->name);
getchar();
return 0;
}
100 BETA
What will be the output?
#include<stdio.h>
struct st
{
int x;
static int y;
};
int main()
{
printf("%d", sizeof(struct st));
return 0;
}
struct {
short s[5];
union {
float y;
long z;
}u;
} t;
Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is
union test {
int x;
char arr[8];
int y;
};
int main()
{
printf("%d", sizeof(union test));
return 0;
}
Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed.
