answersLogoWhite

0


Best Answer

Yes:

struct employeeType

{

string firstName;

string lastName;

int personID;

double monthlyBonus;

}employees;

**Or if you don't want to declare the variable in the struct, erase the bold and add this line to declare the variable:

employeeType employees;

What this does:

Creates array employees from employees[0]-employees[49]

In each location (ie: employees[0]) will be the struct employeeType

employees[0] =

{

string firstName;

string lastName;

int personID;

double monthlyBonus;

}

employees[1] =

{

string firstName;

string lastName;

int personID;

double monthlyBonus;

}

...and so on to:

employees[49]

{

string firstName;

string lastName;

int personID;

double monthlyBonus;

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can the component type of an array be a struct?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How arrays must be handled in c plus plus?

If the array is static it can declared in the structure itself: struct myArrayTag { int num[12]; // array of 12 integers (e.g., 48 bytes). } myArray; If it is dynamic then you must use a pointer and allocate the array outside the structure. You should also maintain a variable in the structure to keep track of how many elements the array currently has: struct myBufferTag { int * array; // Pointer to array of integers. int size; // Size of array (number of elements); } myBuffer;


What is the difference between an array of structures and an array within a structure?

The main differences between an array and a structure are: An Array is a collection of similar data items.An array is derived data type.It behave like a built in data type. An array can be increased or decreased. A structure is a collection of dissimilar data items.It is a user defined data types.It must be declared and defined.A structure element can be added if necessary.


What is the difference between class and struct?

The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color. Although it is possible to represent a point as a class, a struct is more efficient in some scenarios. For example, if you declare an array of 1000 Point objects, you will allocate additional memory for referencing each object. In this case, the struct is less expensive. When we create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized. It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values. It is an error to initialize an instance field in a struct. There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object. A struct can implement interfaces, and it does that exactly as classes do. A struct is a value type, while a class is a reference type.


How do you access elements of array of structure in a function?

For example: struct { int fld; } v[2]; v[0].fld = 1;


Which of the following is not a variable data type real integer number or string?

FILE, struct stat and struct tm are some examples.

Related questions

Non primitive data type?

Struct or array.


Is array is structure or not?

Array is not a struct. Array only has one datatype, struct has arbitrary different datatypes.


Explain the various declaration in array in c?

There is only one type of array-declaration: the one with the brackets. The elements the of array can be of (almost) any type, provided that its size is known by the compiler, so the followings are illegal: struct Str1; typedef int intfun (void); void v_array [4]; /* illegal */ struct Str1 s_array[10]; /* illegal */ intfun fun_array [3]; /* illegal */ But pointer-arrays can be declared with these types: void *pv_array[4]; struct Str1 *ps_array[10]; intfun *pfun_array [3];


How are array of structure variables defined?

struct Foobar myarray [32]; or struct { int foo; double bar; } myarray [32];


What is meant by array with in structure in c language?

It means a structure has a member that is an array: typedef struct foo { int x[42]; // an array of 42 integers // other members... };


What is the difference between an array and structure?

An array is a collection of related data elements of same type.Structure can have elements of different types.An array is a derived data type.A structure is a programmer-defined data type.A struct can contain multiple data types, whereas an array can not.


How arrays must be handled in c plus plus?

If the array is static it can declared in the structure itself: struct myArrayTag { int num[12]; // array of 12 integers (e.g., 48 bytes). } myArray; If it is dynamic then you must use a pointer and allocate the array outside the structure. You should also maintain a variable in the structure to keep track of how many elements the array currently has: struct myBufferTag { int * array; // Pointer to array of integers. int size; // Size of array (number of elements); } myBuffer;


How can a structure be passed as an argument to a function?

A structure is like an array. You can only pass its address. struct _mystruct { int p; ... } mystruct; myfunction (&struct _mystruct mystruct s) { s.p; ... }


What is the difference between an array of structures and an array within a structure?

The main differences between an array and a structure are: An Array is a collection of similar data items.An array is derived data type.It behave like a built in data type. An array can be increased or decreased. A structure is a collection of dissimilar data items.It is a user defined data types.It must be declared and defined.A structure element can be added if necessary.


Can object have array of characters?

If by an object you mean a class or a struct, yes they can. Define the char array like you normally would but don't intialize any data into it. Do this in the constructor


What is the difference between class and struct?

The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color. Although it is possible to represent a point as a class, a struct is more efficient in some scenarios. For example, if you declare an array of 1000 Point objects, you will allocate additional memory for referencing each object. In this case, the struct is less expensive. When we create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized. It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values. It is an error to initialize an instance field in a struct. There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object. A struct can implement interfaces, and it does that exactly as classes do. A struct is a value type, while a class is a reference type.


How do you write an algorithm that puts a list of names in ascending order?

In C language, you can use the string comparing method/*try it, you,ll understand, anr this is not a example done by me. this is the example which i used to learn it*/#include #include #include /* qsort int comparison function */int int_cmp(const void *a, const void *b){const int *ia = (const int *)a; // casting pointer typesconst int *ib = (const int *)b;return *ia - *ib;/* integer comparison: returns negative if b > aand positive if a > b */}/* integer array printing function */void print_int_array(const int *array, size_t len){size_t i;for(i=0; iprice - 100.f*ib->price);/* float comparison: returns negative if b > aand positive if a > b. We multiplied result by 100.0to preserve decimal fraction */}/* qsort struct comparision function (product C-string field) */int struct_cmp_by_product(const void *a, const void *b){struct st_ex *ia = (struct st_ex *)a;struct st_ex *ib = (struct st_ex *)b;return strcmp(ia->product, ib->product);/* strcmp functions works exactly as expected fromcomparison function */}/* Example struct array printing function */void print_struct_array(struct st_ex *array, size_t len){size_t i;for(i=0; i