Wednesday, 27 June 2018

Ch-10 Structure and Union


MCQ
Which of the following cannot be checked in a switch-case statement?
A) Character
B) Integer
C) Float
 D) enum
True false
1. Does the data type of all elements in the union will be same?
2.. typedef is used to give a new name to a known data type.
3. In a union, space is allocated to every member individually.
4. The size of a structure can be determined by both size of variable name and size of (struct tag).
5. Structures can have bit fields.
6.  A structure can contain similar or dissimilar elements.
7. A structure can contain similar or dissimilar elements
8. A structure can contain pointer to itself.
9. Size of all elements in a union should be same.
10. Size of a pointer is equal to the data type it points to.

Match the following
1.        
union
a)       
Is different memory location that is used by several different variables, which may be of different type
2.        
typedef
b)       
Is  a memory location that is used by several different variables,which may be of different type
3.        
A self refrential structure is
c)        
Can be used to create variables of old types
4.        
This concept is borrowed from structure for constructing data type.
d)       
Contains pointer to itself.
5.        
structure
e)       
Array
6.        
The purpose of library function fflush() is
f)        
structure
7.        
A group of related data items
g)       
union
8.        
Structure in c Can be used with
h)       
To clear the specified buffer
9.        

i)         
union
10.    
P->member_name
j)         

11.    
Space for one member only
k)       
(*p).member_name

Fill in the blanks
A.       
unary
B.       
pointer
C.       
typedef
D.       
(*t)
E.        
enum
F.        
typeDef
G.      
semicolon
H.       
Void pointer
I.         
structure
J.         
semicolon
K.       

L.        
declaration
M.     

N.      

O.      

P.       


1. _________keyword is ued to declare user-defined data type.
2. _______is used to club variables of different data types as a unit.
3. type-casting is a _______operator.
4. __________keyword allows user to define  an identifier that would represent an existing data type.
5. All buffers are cleared when a ____________closed.
6. for_____and static variables,initializers must be constant expression.
7. if “t” is a pointer to a structure then “t->” is the same as_________.
8. the statement struct point {int x,y;}is a structure_____________.
9. The closing brace of a structure is followed by ____________.
10. structure definatin must be end with ___________.
Q/A
1. Write a program to copy a file into another file.
2. Write a program to create a structure Employee having empCode, name, department, address and salary as its members. Read the details for 10 employees and then display them.
3. Write a C program to find size of structure without using sizeof operator
4.  Enumerate the difference between: i) structures and union ii) union and enum
5.  Write a program which asks the user to enter the name and age of persons in his group. The numbers of persons is not known to the user in the beginning of the program. The user keeps on entering the data till the user enters the age as zero. The program finally prints the average age.
6. Define a structure of student with the following fields: rollNo, name and marks. Write a program to read and store the data of at most 30 students in an array. Also display the average marks of the students.
7.  Define two structures Metric and British that store distances. The Metric stores values in meters and centimeters and the British stores values in feet and inches. Write a program that reads both structure variables and add values contained in one variable of Metric to the contents of another variable of British. The program should display the result in both: equivalent centimeters and equivalent inches.
8. What is meant by structure data type? How do we reference the elements of a structure? Give example of how a value of a structure can be assigned to another structure.
9. Define a structure of employees of an organization with the following fields: Empno, Empname, Date_of_joining, Salary, Department Write a program which accepts names of ten employees and print them on the screen.
10. Write a program which asks the user to enter the name and age of persons in his group. The number of persons is not known to the user in the beginning of the program. The user keeps on entering the data till the user enters the age as zero. The program finally prints the average age.
11. Define a structure that describes a hotel. It should have members that include the name, address, grade, average room charge and number of rooms. Write a function to perform the following tasks.
12. Define a structure Time having integer data members hour, minute, second. Write a program to enter two variables of the type Time and then add these two variables and store the result into third variable. Also validate the second and minute of the result and print it.
13.  What is union data type? Define a union ‘u’ to hold a integer, float and character variable







No comments:

Post a Comment

ch-12 File Handling

Mcq 1. What does fp point to in the program?   #include<stdio.h> int main() {   FILE *fp;   fp=fopen("trial",...