WorksheetsProblem Solving and C Programming-Assignment 5
Total questions: 10
Worksheet time: 5mins
Which keyword is used to define a structure in C?
struct
record
data
union
Which of the following correctly declares a structure?
struct student { int roll; char name; };
struct student ( int roll, char name );
student struct { int roll; char name; };
struct { int roll; char name; } student;
How do you access a structure member using a structure variable s?
s->name
s.name
s:name
$#name
In a union, the size of the union is equal to:
Sum of all members
Size of the smallest member
Size of the largest member
Always 4 bytes
Which keyword is used to define a union?
struct
union
type
obj
Which function is used to allocate memory dynamically?
malloc()
scanf()
sizeof()
printf()
malloc() returns:
a pointer to the allocated memory
the size of the allocated memory
an integer value
a boolean value
Which function is used to free dynamically allocated memory?
delete()
free()
remove()
dispose()
What is the correct way to allocate memory for 10 integers?
int *p = malloc(10);
int *p = malloc(10 * sizeof(int));
int p = malloc(sizeof(int));
int *p = malloc(int);
What is the correct way to access a structure member using a pointer ptr?
ptr.name
*&ptr.name
ptr->name
*ptr.name
