Structure Practice Questions
1. What is structure? Explain the C syntax of structure declaration
with example.
2. Explain Nested structure with example.
3. What do you mean by structure members?
4. What is the difference between structure variable declaration and
initialization?
5. Write a C program to store and print name, SRN, subject and FSA
marks of students using structure.
6. Explain the difference between array and structures.
7. Explain with example how to use typedef for structures.
8. Write a program that takes two inputs from the user: a distance in
miles and a distance in kms. Use the concept of structures and
function to find the difference in miles.
9. How to copy and compare structure variables? Illustrate with
example.
10. Why strcpy() should be used to modify the content of structure
member if it is a array?
11. Write a program that takes as input two-time instants (let say:
t1(h1,m1,s1) and t2(h2,m2,s2) where h, m and s are hours, minutes
and seconds resp.) and finds the difference between them (t1-t2) using
the concept of structures.
INPUT: Enter hrs, mins, secs for t1: 03 20 50 Enter hrs, mins, secs
for t2: 02 10 30
OUTPUT: Difference= 1:10:20
12.Number of bytes in memory taken by the below structure is?
struct test
{
int k;
char c;
};
13. Explain array of structure with an example.
14.Write a C program to maintain a record of N students details using
an array of structures with four fields (SRN, name, ISA marks and
grade). Assume appropriate data type for each field. Print the marks of
the student (given the student name as input).
15. Write a program to maintain a record of N employee detail using
an array of structures with three fields (E_id, name , salary) and print
the details of employees whose salary is above 2000.
16. How structure variables(objects) are passed as an argument to a
function?
17.Write a C program to define an array of structure with members
roll_no, name and marks for 10 students. Pass this array of structure
to a function to sort the records based on marks in non increasing
order.
18. Program to read and display the details of n books using
functions.
19. Define a named structure containing a string field for a name, an
integer for feet, and another for arms. Use the new type to define an
array of about 6 items. Fill the fields with data and print them out as
follows. A human being has 2 legs and 2 arms. A dog has 4 legs and 0
arms. A television set has 4 legs and 0 arms. A chair has 4 legs and 2
arms. etc.
20.The correct syntax to access the member of the ith structure in the
array of structures is?
Assuming: struct temp
{
int b;
}s[50];
21.Program to read and display the details of n books using functions.
Clearly separate interface and implementation.
22.Program to display all information about a student who has scored
highest marks in a class. Consider inputs: 5 students (info.- name,
roll_no, dob, marks scored in 5 different subjects)
23. Program to store the details of 5 flights. Also display all flights
information sorted in order of their arrival times.
24. Create a structure to maintain the details of bank account(Account
number ,Name, type Balance) and display insufficient fund if the
balance is less than or equal to zero.
25. Create the structure to store the details of employees with details:
(Emp_Id,Emp_name,Emp_phone,Emp_rewardpoint). Read the details
of n employees and if the employee has got rewardpoints more than
1000, then display a message that “Gift voucher has been mailed “
26.Create a structure called Book with members as Book_name,
Author_name, Edition, Publication, year and price. Show the menu to
the user to do the following: Read book data, Display the book data if
the user enters the book name. Display appropriate message.
27. Write a program to create a structure called weather_Report with
data members rainfall, temperature and city name. Create a function
to read and display the details of 3 cities. Also write a function to
display the city name with maximum temperature.
28. Create a user defined data type for date. Write a function which
will increment the date by 1