UNIT 1 UNIT 2 UNIT 3 UNIT 4 UNIT 5 UNIT 6 UNIT 7 UNIT 8
Home Online Quiz Lab Programs Previous Questions Resources Glossary Syllabus Faculty Team

Latest News

Lesson PPTs have been uploaded to Resources Section.


Teaching material,Tutorials and Practice problems of all UNIT's are added.


ebooks have been uploaded to Resources Section.



UNIT 4


TOPICS TO BE COVERED IN THIS UNIT:

  1. Derived types - structures
  2. Declaration, definition and initialization of structures, accessing structures
  3. Nested structures
  4. Arrays of structures
  5. Structures and functions
  6. Pointers to structures
  7. Self referential structures
  8. Unions
  9. Typedef, bitfields


TEACHING MATERIAL

Unit 4 Teaching Aids - Click Here


TUTORIAL MATERIAL

Tutorial 1


  1. A structure is a -------------- data type.
  2. How do we declare a structure?
  3. Identify each part defined in the following structure
    Struct book --------------->
    {
    Char title [15];------------------>
    Char author [15]; ----------------->
    Float price; ---------------------->
    }book1, book2, book3; ------------------->
    
  4. We can access structure members by making use of -----------operator.
  5. What are the different ways used to declare structure variables?
  6. A structure is to be declared as -------when it is used inside a function.
  7. Declare a structure student with members as:
    1. Rollno
    2. branch
    3. Marks
    4. grade
  8. Declare the same structure as mentioned above and initialize the members with values and print them.

Tutorial 2


  1. If we declare an array as a structure variable then the members of the structure are accessed by array by making use of __________ operator.
  2. Give details of 4 students in a structure and access the details by defining array as structure variable?
  3. Struct marks
    {
    int numbers;
    float  subjects[3];
    }
    Student[3];
    In the above structure how the member subjects will be accessed by the structure variable students?
  4. Define a structure employee and within that structure define another structure salary which gives the salary details of the employee?
  5. The numbers of a structure can be accessed using _______ operator when the structure variable is declared as pointer.
  6. Write a program to create a structure inventory which contains the following members
    1. name
    2. number
    3. price
    Access the members of the structure by declaring a pointer as structure variable.

Tutorial 3


  1. If any member of a structure is pointer to the same structure then it is known as _________ structure.
  2. union marks
    {
    Int rollno ;
    Float subjects[3];
    Char name;
    }
    Student;
  3. How many bytes of memory space is required for the above declared union?
  4. What is the difference between structure and union?
  5. By making use of typedef declare an identifier num for data type int.now declare two variables of type num?
  6. Write the general form of bitfield definition?
  7. Struct details
    {
    Unsigned int age=7;
    Unsigned int children=3;
    Unsigned gender=1;
    };
    What is the range of each member of the above structure?

PRACTICE PROBLEMS

Beginner Problems


  1. Write a program to use structure within structure. Display the contents of structure elements.
  2. Write a program to display the size of a structure.
  3. Find out errors if any in the following program:
  4. 	#include
    	main()
          {
    	struct xx
    	{
          int x=3;
          char name[]='hello';
     	};
    	struct xx s;
    	printf("%d",s.x);
    	printf("%s",s.name);
          }
    
  5. Find out errors if any in the following code snippet:
    	struct emp
    	{
      	  int ecode;
       	 struct emp e;
    	};
    
  6. Differentiate structure and union.

Intermediate Problems


  1. Define a structure to represent a data. Use your structures that accept two different dates in the format of mmdd.
    And do the following: Write a C program to display the month names of both dates
  2. Write a program to create an array of student structure objects and to find the highest marks scorer.
    The fields in the student structure are: name, age and marks.
  3. Find out the errors if any in the following code snippet:
    	typedef struct
    	{
     	   int data;
     	   NODEPTR link;
     	} *NODEPTR;
    
  4. Predict the output of the following program
    	#include
    	int main()
    	{
    	  struct value
     	 {
       	 int bit1:1;
       	 int bit3:4;
       	 int bit4:4;
     	 }bit;
     	 clrscr();
     	 printf("%d\n",sizeof(bit));
     	 return 0;
    	}
    
  5. Predict the output of the following program
    	#include
    	#include
    	struct emp
    	{
      	int len;
      	char *name;
    	};
    	int main()
    	{
    	  char newname[]='India';
     	 char *buff=malloc(sizeof(struct emp)+strlen(newname)+1);
      	struct emp *p = (struct emp*)buff;
     	 clrscr();
     	 p->len=strlen(newname);
    	  strcpy(p->name,newname);
     	 printf("%d\t%s\n",p->len",p->name);
     	 free(p);
     	 return 0;
    	}
    

Advanced Problems


  1. Write a C program to read the information from the keyboard in which the “Employee” structure consists of
    employee name, code, department (which is again a structure), address (another structure), designation
    and salary. Construct an array of structures that stores ‘n’ employees information and write a program to
    carry out operations like inserting a new entry, deleting entry.
  2. Write a C program to add, subtract and multiply the given complex numbers. Define functions and print with structures as arguments.
  3. The annual examination is conducted for 50 students for ‘n’ subjects. Write a program to read the data and determine the following:
    1. Total marks obtained by each student.
    2. The highest marks in each subject and the Roll Number of the student who secured it.
    3. The student who obtained the highest total marks.
  4. Predict the output of the following program and analyze it.
    	#include
    	int main()
    	{
    
    	struct value
      	{
      	  int bit1:1;
       	 int bit3:4;
       	 int bit4:4;
     	 }bit={1,2,2};
     	 clrscr();
     	 printf("%d\t%d\t%d\n",bit.bit1,bit.bit3,bit.bit4);
      	return 0;
    	}
    
  5. Predict the output of the following program and analyze it.
    	#include
    	#include
    	struct emp
    	{
     	 int len;
     	 char name[1];
    	};
    
    	int main()
    	{
      	 char newname[]='CLanguage';
     	 struct emp *p = (struct emp*)malloc(sizeof(struct emp)-1+ strlen(newname)+1);
     	 clrscr();
     	 p->len=strlen(newname);
     	 strcpy(p->name,newname);
     	 printf("%d\t%s\n",p->len,p->name);
      	 return 0;
    	}
    
    

This Page Is Designed By Santosh

Copyright (c) Aditya Engineering Colleges, Surampalem. All rights reserved.
Development Team