C PROGRAMMING: Declare a structure whose tag name is Emp and that contains these
ID: 671668 • Letter: C
Question
C PROGRAMMING:
Declare a structure whose tag name is Emp and that contains these fields (in the following order): a double field named d, acharacter pointer named str, and an array of eleven integers named arr.
In addition, declare a array named emp of 30 of these structures. Assign the value 12 to the last element of the arr field of the last element of emp. Assign 3.5 to the d field of the first emp element . Assign the string Hello to the k'th element of emp (assume k has been declared as an integer variable and assigned a value in the range of the array elements ).
This is what I have so far:
struct Emp {double d; char *str; int arr[11];};
//Error message :
emp[30];
//assigning 12 to the last element of the arr field
emp[29].arr[10]=12;
//assign 3.5 to the d field of the first emp element.
emp[0].d=3.5;
//assing string to k'th element of emp
emp[k].str="Hello";
Explanation / Answer
#include<stdio.h>
struct Emp
{
double d;
char *str;
int arr[11];
};
int main(void)
{
Emp emp[30];
emp[29].arr[10] = 12;
emp[0].d = 3.5;
int k = 15;
emp[k].str = "Hello";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.