Define structures in c++, C/C++ Programming

Assignment Help:

Structures

A structure is a user-defined data type, which may have different data types as its members. Creating a structure is a two-part process. First, a structure template is explained. This template gives a lot of information to the compiler. For instance, how it is kept in the memory? How many member variables are there in this composite data element? What are the types of its member variables? For data types such as int, float, double, char this information is built into the compiler. But for the user-defined data types like structures, it has to be given to the compiler. This is given in the definition of the structure template. This template makes a new data type. Variables of this new data type can then be declared and used like basic data types.

e.g.

                struct Student

                 {

                                int Rollno;

                                char Name[15];

                                int Marks[6];

                                float percent;

                };

The above example depicts structure called students with enclosed data variables. The keyword struct is used to explain a structure template. Student is a name or tag. The variables of this type can be declared as follows :

 

                struct Student s1,s2;

[or ]

In C++ you can even omit the struct tag and declare the variables as,

                Student s1 = ( 100, "Sanket" , 20,10,30,40,50,60, 35.0};

                Student s2,jack;

                Student *sptr = &s1;

                Student s[100];

 


Related Discussions:- Define structures in c++

Assigment, Hi is there any chance to get assignment for fresher tutor

Hi is there any chance to get assignment for fresher tutor

Logic, to calculate the amount to be paid by a customer buying yummy cupcak...

to calculate the amount to be paid by a customer buying yummy cupcakes for his birth day party

C program to check prime numbers , C Program to check PRIME NUMBERS   ...

C Program to check PRIME NUMBERS   main() {           int i,k,r,flag;           clrscr();           printf("ENTER THE NO. TO CHECK IT IS PRIME OR NOT: ");

Write a program of constructors and destructors, Write a program of constru...

Write a program of constructors and destructors Make a class drugs having encapsulated data for medicine name, whether solid or liquid, price and purpose of use. From this clas

Array, how to do an array

how to do an array

Programming and solving problems, One person who is specialist at programmi...

One person who is specialist at programming and solving problems with a computer Project Description: Dear Potential computer, hardware, programming and software genius, I

Explain pure virtual functions, Pure Virtual Functions An abstract clas...

Pure Virtual Functions An abstract class is one, which is used just for deriving some other classes. No object of this class is declared and used in the program. Likewise, ther

Cloud computing, hi Bhasker, as we spoke tru phone ,we need a project usin...

hi Bhasker, as we spoke tru phone ,we need a project using cloud computing .we need to present a protoype or demo on it (any thing using cloud should be fine)(ex: P2p)

Generate a class node that contains an integer id, Generate a class node ...

Generate a class node that contains an integer id, a position (x, y)  and a vector of 0 5,  generate a set of  x nodes each with random connectivity n.    Implement an algorith

Explain the macros, Explain the Macros? Preprocessor' is a translation ...

Explain the Macros? Preprocessor' is a translation stage that is applied to your source code before the compiler proper gets its hands on it. Usually the preprocessor performs

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