<< Chapter < Page Chapter >> Page >
struct Date {int day; int month;int year; };

We can now use this Date type, together with other types, as members of a Student type which we can declare as follows:

struct Student {char studentID[10];char name[30];float markCS ; Date dateOfBirth;};

Or

struct Student {char studentID[10];char name[30];float markCS; struct Date {int day; int month;int year; } dateOfBirth;};

We can also declare structured variables when we define the structure itself:

struct Student {char studentID[10];char name[30];float markCS ; Date dateOfBirth;} a, b, c;

C permits to declare untagged structures that enable us to declare structure variables without defining a name for their structures. For example, the following structure definition declares the variables a, b, c but omits the name of the structure:

struct {char studentID[10];char name[30];float markCS ; Date dateOfBirth;} a, b, c;

A structure type cannot contain itself as a member, as its definition is not complete until the closing brace (}). However, structure types can and often do contain pointers to their own type. Such self-referential structures are used in implementing linked lists and binary trees, for example. The following example defines a type for the members of a singly linked list:

struct List { struct Student stu; // This record's data.struct List *pNext; // A pointer to the next student. };

Referencing structure members with the dot operator

Whenever we need to refer to the members of a structure, we normally use the dot operator.

For example, if we wanted to access the number member of newStudent we could do so as follows:

newStudent.studentID

We can then access the member as if it were a normal variable. For instance, we can write to this member as follows.

newStudent.studentID= “C0681008”;

We can also read from the member in a similar fashion.

printf("Student identification: %s", newStudent.studentID);

The following code outputs the contents of an Student structure.

printf("Student Details\n"); printf("Identification: %s\n", newStudent.studentID);printf("Name: %s\n", newStudent.name); printf("Mark: %.2f\n", newStudent.markCS);printf("Date of Birth: %i/%i/%i\n", newStudent.dateOfBirth.day,newStudent.dateOfBirth.month, newStudent.dateOfBirth.year);

Suppose we wish to input the details of this employee from a user. We could do so as follows.

Student newStudent; printf("Enter student identification: ");scanf("%s",&newStudent.studentID); printf("Enter student name: ");fflush(stdin);gets(newStudent.name); printf("Enter mark for Introduction to computer science course: ”);scanf("%f",&newStudent.markCS); printf("Enter birth date (dd/mm/yyyy): ");scanf("%i/%i/%i",&newStudent.dateOfBirth.day,&newStudent.dateOfBirth.month,&newStudent.dateOfBirth.year );

Initializing structure variables

When we declare a new variable of a basic data type we can initialize its value at declaration. We can also initialize structure variables at declaration as shown below.

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Introduction to computer science. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10776/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to computer science' conversation and receive update notifications?

Ask