Given below is a structure definition. struct Contact ( char name[20] int phone_
ID: 3907302 • Letter: G
Question
Given below is a structure definition. struct Contact ( char name[20] int phone_num; int postalcode; The members name, phone_num and postalcode are used to store data such as name (e.g. Alan), phone number (e.g. 87654345) and postal code (e.g. 743156) respectively. Write the C code to declare a structure named mycontacts of type struct Contact and assign the following member data to the structure you have declared. (Assume that headers and string.h> have been included in the main code) Contact Name: Celeste Phone: 87453867 Postal Code: 721013Explanation / Answer
C code:
#include <stdio.h>
//structure definition
struct Contact
{
char name[20];
int phone_num;
int postalcode;
};
//main method
int main()
{
//structure declaration- named mycontacts
/* and assiging the data to the structure*/
struct Contact mycontacts = {"Celeste",87453867,721013};
// printing
printf("Contact ");
printf("Name: %s ",mycontacts.name);
printf("Phone: %d ",mycontacts.phone_num);
printf("Postal Code: %d ",mycontacts.postalcode);
return 0;
}
Output:
Contact
Name :Celeste
Phone 87453867
Postal Code: 721013
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.