Learning and Reading Stuffs by Knowledge flow

Learn Significant Concepts About Structure Of C Programming

Structures in C
Structure is a user defined data type in C which consent to you to unite dissimilar data types to accumulate an exacting type of record. Structure helps to build a compound data type in more significant way. It is somewhat comparable to an Array. The only dissimilarity is that array is used to accumulate compilation of comparable data types while structure can store set of any type of data. Structure is used to symbolize a proof. Suppose you want to accumulate documentation of Student which contain of student name, roll number, address and age. You can describe a structure to hold this information.
Structure in C Programming is a compilation of variables of dissimilar category beneath a solitary name. For instance: You want to accumulate some information about a person: his/her name, salary and citizenship number. You can simply produce dissimilar variables name, salary and citNo, to accumulate this information individually. Though, in the future, you would desire to accumulate information concerning various persons. Now, you'd require producing different variables for all information per being: name1, name2, salary1, salary2, citNo1, citNo2, you can simply envision how large and confused the system would seem. Also, since no relative connecting the variables information would survive, it's departing to be an intimidating task.
An improved advance will be to have a compilation of all connected information beneath a single name Person, and use it for all being. Now, the code looks much cleaner, legible and competent as well. A better move towards will be to have a compilation of all connected information under a single name Person, and utilize it for every being. Now, the code appears much cleaner, legible and competent as well. This compilation of all connected information beneath a solitary name Person is a structure.
Structure Definition in C Programming
Keyword struct is used for generating a structure in C


struct structure_name 
{
    data_type member1;
    data_type member2;
    .
    .
    data_type memeber;
};


Here we can produce the structure in C for a person as declared above as:

struct person
{
    char name[50];
    int citNo;
    float salary;
};
int main()
{
    struct person person1, person2, person3[20];
    return 0;
}

In a C language one more method of producing a structure variable is:

struct person
{
    char name[50];
    int citNo;
    float salary;
} person1, person2, person3[20];

In both cases two variables person1, person2 and an array person3 containing 20 fundamentals of sort struct person are formed.
Accessing Members of a Structure in C
There are two category of operators used for contacting parts of a C programming.
Member operator (.)
Structure pointer operator(->)
Any member of structures in C can be contacted as:
structure_variable_name.member_name
Suppose, we want to contact salary for variable person2 then it can be admittance as:
person2.salary
Keyword Typedef While Using Structure in C Language
Structure in C language characters struct structure_name variable_name; to declare a structure variable isn't perceptive as to what it indicates, and obtains some substantial sum of enlargement time.
Passing Structures to a Function
There are primarily two ways to exceed structures to a function:
Passing by value 
Passing by reference

No comments

Powered by Blogger.