Thursday 15 April 2021

Strucature Notes : All in 1 page


Structure :

Structure in c is a user-defined data type that enables us to store the collection of different data types. Each element of a structure is called a member.

The struct keyword is used to define the structure.


Syntax :

struct [structure Name] {


   member definition;

   member definition;

   ...

   member definition;

};


OR

struct [structure Name] {


   member definition;

   member definition;

   ...

   member definition;

} obj;



e.g

struct Books {

   char  title[50];

   char  author[50];

   char  subject[100];

   int   book_id;

} book;  


Access members of a structure

There are two types of operators used for accessing members of a structure.

  1. . - Member operator
  2. -> - Structure pointer operator (will be discussed in the next tutorial)


book.name or book->name



Program :





Memory Management for Array Of Structure :


Why structs in C?

Suppose, you want to store information about a person: his/her name, citizenship number, and salary. You can create different variables namecitNo and salary to store this information.

What if you need to store information of more than one person? Now, you need to create different variables for each information per person: name1citNo1salary1name2citNo2salary2,etc.

A better approach would be to have a collection of all related information under a single name Person structure and use it for every person.



Assignment : 

1. Create Menu Driven Program for Stud Database System Using Structure.


2 Create Menu Driven Program For Bank Manegment.
Ans : 




 

No comments:

Post a Comment