Structures, C/C++ Programming

Assignment Help:

  A more advanced data type is the structure; here we can define a template as a collection of different variables e.g.
 
  struct birthdate
  {
    int month;
    int day;
    int year;
  };
 
  Here the template birthdate consists of three separate content variables namely month   , day , year .We can access each part of the structure by means of the dot '.' operator i.e. after we have allocated the variable to be used to hold the structure.
 
    struct  birthdate john;
 
We can access all the details i.e.
 
      john.month  = 12;
      john.day = 28;
      john.year = 52;
 
This is identical to using a two dimensional array to hold the values
 
      john[0][0]  could hold month
      john[0][1]  could hold day
      john[1][0]  could hold year

However using a structure template we can use different types in the same structure
   
    struct details
    {
    int month;
    int day;
    int year;
    char * name;
    };
 
It is possible to use structures defined as pointers, if you wish to want to use the actual address.
 
  
    main()
    {
      struct *records 
      {
      int month;
      int day;
      int year;
      char * name;
      };
 
  Here we have a structure assigned to a pointer record. In order to access the content month we use must dereference the pointer and access the element i.e.
 
      (*records).month 
 
This is often replaced with a -> symbol (minus followed by >) i.e.
 
      records -> month.


Related Discussions:- Structures

Write the program of function templates, Consider the following example: ...

Consider the following example: int max(int x, int y)                  {                                 return ( x > y) ? x : y ;                  }   float max

Resection method, recsection method source code for searching position

recsection method source code for searching position

What is memory allocation, What is memory allocation? Memory Allocation...

What is memory allocation? Memory Allocation : It is the method of allocating memory storage to program in such that the program can be run.

C program to demonstrate call by reference, C program to demonstrate call b...

C program to demonstrate call by reference: void disp(int *,int*,int*,int*); void main() {                 int a=2,b=3, sum,mul;                 printf("Enter 1st n

#title., A student apears in exam of math, physics, and chemistry. Write a...

A student apears in exam of math, physics, and chemistry. Write a program to find the total marks aa student has aqueired find the average.

Rules of operator overloading, Rules of Operator Overloading It is ...

Rules of Operator Overloading It is a function defined to an operator with new term or meaning. It cannot produce new operator. It cannot modified the meaning of th

What is some reward/drawback of using friend functions?, A: They present a ...

A: They present a degree of freedom in the interface design options. Member functions & friend functions are equally privileged (100% vested). The major difference is that a fri

Change to palindrome, convert string s into palindrome by doing character r...

convert string s into palindrome by doing character replacement

Example program of c programming, Write a c program to determine interchang...

Write a c program to determine interchanged values between two variables?[Hint - if loop] What will be the output of the program? How many times this loop will execute? Wr

Program to calculate pie, This problem familiarizes you with using random n...

This problem familiarizes you with using random numbers in C++. The program is to compute a good approximation of π using a simulation method called "Monte Carlo". The following fi

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd