বিভিন্ন ধরণের 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

The #define and #undef Directives

The #define and #undef Directives

The #define directive is the most common preprocessor directive, which tells the preprocessor to replace every occurrence of a particular character string (that is, a macro name) with a specified value (that is, a macro body).

The C Preprocessor Versus the Compiler

The C Preprocessor Versus the Compiler

One important thing you need to remember is that the C preprocessor is not part of the C compiler.

What Is the C Preprocessor?

If there is a constant appearing in several places in your program, it's a good idea to associate a symbolic name to the constant, and then use the symbolic name to replace the constant throughout the program. There are two advantages to doing so. First, your program will be more readable.

Exercises : Answer the following Question

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

Question and Answer

    Q Why is random access to a disk file necessary?