About Me

Hey friends! My name is yuvraj basnet. I'm going to introduce myself.I have born and grown up in india(chandigarh) and I'm studying second year of B.C.A computer science field. My father serving in indian air force. My mother has been taking care of house hold. I am a friendly person, good thinker, I can work for longer hours without any break, only if I'm interested in that...My life style is very simple.

STRUCTURES IN C


array of structures, c programming basics, c programming basics, c programming code blocks

In this tutorial you will learn structures in C programming language, how to define structure in C, Accessing Structure members with examples.

Passing function by value and address.

So, lets get started


STRUCTURE:
1)A Structure is a user defined datatype, which is mostly used to stores a collection of    different types of data. 

2) The structure is similar to an array. The only difference is that structure can stores
    different kinds of data and array is used to store same datatypes.

3) struct keyword is used to declare the structure in C.

4) All the variables inside the structure are called members of the structure.

5) structure can allocate different memory to different members of the structure.


Uses of structures in C:

1. C structures can be used to store huge data. 
2. C structures can be clear output screen content.
3. C structures can be used to check computer's memory size.
4. C structures can interact with keyboard and mouse to store the data.

SYNTAX OF STRUCTURE:



DECLARE STRUCTURE USING NORMAL AND POINTER VARIABLE:



INITIALIZING STRUCTURE USING NORMAL AND POINTER VARIABLE:



ACCESSING STRUCTURE MEMBER USING NORMAL AND POINTER VARIABLE:



PROGRAM TO IMPLEMENT STRUCTURE:

This program is used to store and access “Website, subject and price” for course. We can also store and access these data for many students using array of structures. 


OUTPUT:


PROGRAM TO IMPLEMENT STRUCTURE OF ARRAY IN C:

This program is used to store and access “id, name and percentage” for 3 students. Structure array is used in this program to store and display records for many students. You can store “n” number of students record by declaring structure variable as ‘struct student record[n].


OUTPUT




PASSING STRUCTURE TO FUNCTION:



1. Passing structure to function by value.
2. Passing structure to function by address.


Example program – passing structure to function in C by value:
In this program, the whole structure is passed to another function by value with all members and their values.


OUTPUT:

Example program – passing structure to function in C by ADDRESS:
In this program, the whole structure is passed to another function by address. It means only the address of the structure is passed to another function and this structure is accessed from called function by its address.


OUTPUT:











Post a Comment

0 Comments