0% found this document useful (0 votes)
11 views4 pages

Department of Electronics & Communication Engineering

This document is a tutorial for B. Tech. Sem.I (EC) students at Dharmsinh Desai University for the academic year 2024-2025. It includes multiple-choice questions, true/false statements, output prediction exercises, and programming tasks related to structures in C programming. The tutorial covers various aspects of structures, unions, and their applications in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Department of Electronics & Communication Engineering

This document is a tutorial for B. Tech. Sem.I (EC) students at Dharmsinh Desai University for the academic year 2024-2025. It includes multiple-choice questions, true/false statements, output prediction exercises, and programming tasks related to structures in C programming. The tutorial covers various aspects of structures, unions, and their applications in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Department of Electronics & Communication Engineering

(Faculty of Technology, Dharmsinh Desai University, Nadiad)


Academic Year : 2024 - 2025

Tutorial – 10

Subject : PPS
Class : B. Tech. Sem.I (EC)

Q.1 Select the most appropriate option.


(1) Which of the following is the correct way of accessing the members of a structure
variable?
(a) Using dot notation, v.x
(b) Using indirection notation, (*ptr).x
(c) Using selection notation, ptr –> x
(d) All of the above
(2) What is the size of a C structure.?
(a) C structure is always 128 bytes.
(b) Size of C structure is the total bytes of all elements of structure.
(c) Size of C structure is the size of largest element.
(d) D) None of the above
(3) What is the similarity between a structure, union and enumeration?
(a) All of them let you define new values
(b) All of them let you define new data types
(c) All of them let you define new pointers
(d) All of them let you define new structures
(4) Choose a correct statement about C structures.
(a) A structure can contain same structure type member.
(b) A structure size is limited by only physical memory of that PC.
(c) You can define an unlimited number of members inside a structure.
(d) D) All the above.
(5) Choose a correct statement about C structure elements.?
(a) Structure elements are stored on random free memory locations
(b) structure elements are stored in register memory locations
(c) structure elements are stored in contiguous memory locations
(d) D) None of the above.
Q.2 State True or False
(1) A union cannot be nested in a structure
(2) Nested unions are allowed
(3) one of elements of a structure can be a pointer to the same structure.
(4) A structure can be nested inside another structure.
(5) It is not possible to create an array of pointer to structures.
(6) It is legal to copy a content of a structure variable to another structure variable of the
same type.
(7) An array cannot be used as a member of a structure.
Q.3Predict the output.
(1) int main()
{
structure hotel
{
int items;
char name[10];
}a;
strcpy(a.name, "TAJ");
a.items=10;
printf("%s", a.name);
return 0;
}
(2) int main()
{
struct book
{
int pages;
char name[10];
}a;
a.pages=10;
strcpy(a.name,"Cbasics");
printf("%s=%d", a.name,a.pages);
return 0;
}
(3) int main()
{
struct ship
{
int size;
char color[10];
}boat1, boat2;
boat1.size=10;
boat2 = boat1;
printf("boat2=%d",boat2.size);
return 0;
}
(4) int main()
{
struct tree
{
int h;
int w;
};
struct tree tree1={10};
printf("%d ",tree1.w);
printf("%d",tree1.h);
return 0;
}
(5) #include<stdio.h>

int main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
return 0;
}
(6) #include<stdio.h>

int main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}bit={1, 2, 13};

printf("%d, %d, %d\n", bit.bit1, bit.bit3, bit.bit4);


return 0;
}
(7) int main()
{
struct pens
{
int color;
}p1[2];
struct pens p2[3];
p1[0].color=5;
p1[1].color=9;
printf("%d ",p1[0].color);
printf("%d",p1[1].color);
return 0;
}
(8) main ( )
{
union x
{
int a;
float b;
double c;
};
printf("%d\n", sizeof(x));
a.x = 10;
printf("%d%f%f\n", a.x, b.x, c.x);
c.x = 1.23;
printf("%d%f%f\n", a.x, b.x, c.x);
}

Q.4 Do as directed.
(1) Define a structure data type called time_struct containing three members integer hour,
integer minute and integer second. Develop a program that would assign values to the
individual members and display the time in the following form:
16:40:51
(2) Create two structures named metric and British which store the values of distances.
The metric structure stores the values in metres and centimetres and the British
structure stores the values in feet and inches. Write a program that reads values for the
structure variables and adds values contained in one variable of metric to the contents
of another variable of British. The program should display the result in the format of
feet and inches or metres and centimetres as required.
(3) Define a structure that can describe an hotel. It should have members that include the
name, address, grade, average room charge, and number of rooms.
Write functions to perform the following operations:
(a) To print out hotels of a given grade in order of charges
(b) To print out hotels with room charges less than a given value
(4) Define a structure called cricket that will describe the following information:
player name
team name
batting average
Using cricket, declare an array player with 50 elements and write a program to read
the information about all the 50 players and print a team-wise list containing names of
players with their batting average.
(5) Write a C program that prints the size of a structure data type.

* * *

You might also like