Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz on File, Memory Alloc, Preprocessor, Structure & Union

Total questions: 20

Worksheet time: 23mins

Name
Class
Date
1.
The keyword which is used to declare a file pointer in C is
a)
File
b)
file
c)
FILE
d)
File ptr
2.
Where is a file temporarily stored before read or write operation in C language.?
a)
Notepad
b)
Buffer
c)
Hard Disk
d)
RAM
3.
What is the syntax for writing a file in C using binary mode.?
a)
fp=fopen("abc.txt","wr");
b)
fp=fopen("abc.txt","wb");
c)
fp=fopen("abc.txt","wbin");
d)
fp=fopen("abc.txt","b");
4.
What are the C functions used to read or write a file in Text Mode.?
a)
fprintf(), fscanf()
b)
fread(), fwrite()
c)
fprint(), fscan()
d)
read(), write()
5.
Choose a correct syntax for FSCANF in c language.?
a)
fscanf("format specifier",variables, fp);
b)
fscanf(fp,count,"format specifier",variables);
c)
fscanf(fp,"format specifier",variables);
d)
fscanf(variables, fp);
6.
Choose a correct syntax for FPRINTF in c language.?
a)
fprintf("format specifier",variables, fp);
b)
fprintf(fp,count,"format specifier",variables);
c)
fprintf(fp,"format specifier",variables);
d)
fprintf(variables, fp);
7.
Commands that begin with # symbol are called as ________
a)
Hash commands
b)
File Statements
c)
Preprocessor Directives
d)
Special Directory
8.
Identify the correct Statement from the following
a)
#define PI 3.14
b)
#define PI=3.14;
c)
#define "PI=3.14";
d)
#define "PI 3.14";
9.
Identify the conditional compilation statement from the following choices
a)
#define PI 3.14;
b)
#ifndef SELVA
c)
#pragma startup function1
d)
#pragma exit function2
10.
What does the statement #Pragma startup <function_name_1> do?
a)
function_name_1 will be called after the main function is executed
b)
function_name_1 will be called before the main function is executed
c)
function_name_1 will replace the main function's instructions
d)
main function will not allow the function_name_1 to execute
11.
malloc() stands for Memory Allocation, wheras calloc() stands for _______
a)
continuous Allocation
b)
cancel the allocation
c)
contiguous allocation
d)
counter allocation
12.

Can you combine the following two statements into one?

char *p;

p = (char*) malloc(100);

a)
char p = *malloc(100);
b)
char *p = (char) malloc(100);
c)
char *p = (char*)malloc(100);
d)
char *p = (char *)(malloc*)(100);
13.
Array and Structure are group of elements. But they differ from each other by one of the reasons listed. Choose the right option
a)
Array has hetrogenous group of elements, whereas structure has homogenous group of elements.
b)
Structure has hetrogenous group of elements, whereas Array has homogenous group of elements.
c)
Array and Structure differ by their name only.
d)
There is no significant difference
14.
In the declaration statement, struct Student s1,s2; s1 & s2 are called as ______
a)
The members of the structure Student
b)
The value of the structure Student
c)
The variables of the structure Student
d)
The other names for Student structure
15.
The operator which is used to access the members of the structure is _________
a)
dot operator
b)
Assignment operator
c)
& operator
d)
* operator
16.

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;

}

a)

100 BETA

b)
100
c)
Runtime error
d)
Compile time error
17.

What will be the output?

#include<stdio.h>

struct st

{

int x;

static int y;

};

int main()

{

printf("%d", sizeof(struct st));

return 0;

}

a)
4
b)
8
c)
Compile time Error
d)
Run time Error
18.
Structure and Union mainly differ in their memory allocation. If so, which of the following statement is true?
a)
Each member in a structure is assigned with unique storage location
b)
Each member in a Union is assigned with unique storage location
c)
Memory allocated is shared by each member of the structure
d)
Memory is not allocated for Union.
19.

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

a)
22 bytes
b)
14 bytes
c)
18 bytes
d)
10 bytes
20.

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.

a)
12
b)
16
c)
8
d)
Compile Error