বিভিন্ন ধরণের Data Items

Submitted by tushar pramanick on Mon, 01/02/2012 - 16:23

 In Chapter 12, "Storing Similar Data Items," you learned how to store data of the same type into arrays. In this hour, you'll learn to use structures to collect data items that have different data types. The following topics are covered in this lesson:

    Declaring and defining structures
    Referencing structure members
    Structures and pointers
    Structures and functions
    Arrays of structures



Summary

  •     You can group variables of different types with a data type called a structure.
  •     The data items in a structure are called fields or members of the structure.
  •     The struct keyword is used to start a structure declaration or a structure variable definition.
  •     The dot operator (.) is used to separate a structure name and a member name in referencing the structure member.
  •     The arrow operator (->) is commonly used to reference a structure member with a pointer.
  •     A structure can be passed to a function, and a function can return a structure back to the caller.
  •     Passing a function with a pointer that points to a structure is more efficient than passing the function with the entire structure.
  •     Arrays of structures are permitted in C.
  •     You can enclose a structure within another structure. The latter is called a nested structure.
  •     It's legal to put a pointer into a structure even though the pointer may point to another structure that has not been declared yet.
     

Related Items

Adding More Expressions into for

Adding More Expressions into for

The C language allows you to put more expressions into the three expression fields in the for statement. Expressions in a single expression field are separated by commas.

The Null Statement

The Null Statement

Looping Under the for Statement

Looping Under the for Statement

The general form of the for statement is

for (expression1; expression2; expression3) {
   statement1;
   statement2;
   .
   .
   .
}

Using Nested Loops

Using Nested Loops

You can put a loop inside another one to make nested loops. The computer will run the inner loop first before it resumes the looping for the outer loop.

Listing 7.7 is an example of how nested loops work.

 

The do-while Loop

The do-while Loop

You may note that in the for and while statements, the expressions are set at the top of the loop. However, in this section, you're going to see another statement used for looping,