Question

Question 1 Given the declarations: #include <stdio.h> struct STRUCTURE { int aa; char bb[20]; } enum...

Question 1

  1. Given the declarations:
    #include <stdio.h>

    struct STRUCTURE
    {
    int aa;
    char bb[20];
    }
    enum Numbers
    {
    zero, one, two, three
    }
    typedef struct STRUCTURE STR;
    typedef enum Numbers NB;

    STR st1, st2;
    NB value1, value2;

    check the validity of the following assignments:

A) Valid B) Not valid

value1 = four;

value2 = three;

printf (“st1= %d”, st1);

st2.aa = two;

strcpy(st2.bb,"Quiz4");

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1:
Given the declarations:
#include <stdio.h>
struct STRUCTURE
{
int aa;
char bb[20];
}
enum Numbers
{
zero, one, two, three
}
typedef struct STRUCTURE STR;
typedef enum Numbers NB;

STR st1, st2;
NB value1, value2;
check the validity of the following assignments:

1. value1=four
Ans: Invalid.
This is invalid because value1 is of type enum Numbers so accept enum values only. In the enum declaration, we have defined only zero, one, two, and three only but not four. This will raise an error saying four undeclared.

2. value1=three
Ans: Valid
This is Valid because as mentioned three is present in the enum structure so which will not raise an error.

3. printf ("st1= %d", st1);
Ans: Invalid
This will execute but still raises a warning. This is because st1 is a variable of type STRUCTURE which contains an int as well as the char array. Directly using st1 which is a variable of type structure. So this will print some garbage address.

4.st2.aa = two;
Ans: Valid
This is valid because st2 is a variable of type STRUCTURE and the member aa represents int and now we use two which holds the value 2(because as it as of enum type zero holds 0, one holds 1, likewise). This is a valid assignment and holds an int value.

5. strcpy(st2.bb,"Quiz4");
Ans: Valid
This is valid because st2 is a variable of type STRUCTURE and the member bb represents a char array and we are passing a string "Quiz4" which is also of type char array only.so this will execute perfectly.

Please check the compiled program and its output for your reference:
main.c 1 #include <stdio.h> 2 #include<string.h> 3 struct STRUCTURE 4-{ 5 int aa; 6 char bb[20]; 7 }; 8 enum Numbers 9 { 10 z
Output:
As you can see commenting out makes the program run without any errors.
Question 1 ... Program finished with exit code 0 Press ENTER to exit console.
(Feel free to drop me a comment, If you need any help)

Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...

Add a comment
Know the answer?
Add Answer to:
Question 1 Given the declarations: #include <stdio.h> struct STRUCTURE { int aa; char bb[20]; } enum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; };...

    Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; }; void func(struct student stud); int main() { struct student astud; astud.id=9401; strcpy(astud.name, "Joe"); astud.grade = 'A'; func(astud); return 0; } Abdelghani Bellaachia, CSCI 1121 Page: 16 void func(struct student astud) { printf(" Id is: %d \n", astud.id); printf(" Name is: %s \n", astud.name); printf(" Grade is: %c \n", astud.grade); } Modify this program to include the address of a student as a separate structure....

  • Question 1 Consider the following program fragment that defines a self-referential class: #include <stdlib.h> #include <stdio.h>...

    Question 1 Consider the following program fragment that defines a self-referential class: #include <stdlib.h> #include <stdio.h> struct node_int; typedef struct node int *node; struct node_int void *data; node next; typedef struct list_int (node first;} *list; void main(int argc, char *argv[]) list shopping, t; node n; int x=25; shopping=(list) malloc(sizeof(struct list_int)); n= (node) malloc(sizeof(struct node_int)); n->data=shopping; n->next=NULL; shopping->first=n; t=(list) (shopping->first->data); // ***** t->first=NULL; // ***** n->data=&x; printf("%d\n", *((int *) (shopping->first->data))); a What will be displayed on the screen if the above...

  • Enum {FALSE=0, TRUE}; #define MAXBUFF 1024 #define SMALLBUFF 10 /* The LinkNode type is used as a...

    enum {FALSE=0, TRUE}; #define MAXBUFF 1024 #define SMALLBUFF 10 /* The LinkNode type is used as an element of a linked list ** implementation of a stack of tree nodes. */ typedef struct link_t LinkNode; typedef LinkNode *LinkNodePtr; /* The TreeNode type is used as an element of a binary "parse" tree. ** Tree nodes are created while parsing the RPN expression and ** stored on a stack until it's time to place them. */ typedef struct tree_t TreeNode; typedef...

  • I need help on this Systems review please! it's due by midnight monday. Question 1 Not...

    I need help on this Systems review please! it's due by midnight monday. Question 1 Not yet answered Points out of 1.00 Flag question Question text Using these declarations: int * numberPointers[3]; int * pointer; int number; Which of the following statements would generate a warning or error? Select one: a. number = pointer; b. *pointer = number; c. pointer = numberPointers; d. numberPointers[2] = &number; e. a., b., and d. f. a. and c. Question 2 Not yet answered...

  • IN C PROGRAMMING. PLEASE INCLUDE COMMENTS #include #include #include typedef struct Contact_struct { char myName[20]; //name...

    IN C PROGRAMMING. PLEASE INCLUDE COMMENTS #include #include #include typedef struct Contact_struct { char myName[20]; //name of this Contact int numGoals; struct Contact_struct* next; //pointer to the next Contact } Contact; //Contact Constructor void Contact_Create(Contact* thisContact, char thisName[], int thisGoals, Contact* nextContact) { strcpy(thisContact->myName,thisName); thisContact->numGoals = thisGoals; thisContact->next = nextContact; } void Contact_PrintList(Contact* headContact){ Contact* currContact = headContact; while (currContact != NULL){ printf("%s has scored %d goals\n",currContact->myName, currContact->numGoals); currContact = currContact->next; } } int Contact_SumGoals(Contact* headContact){ //Develop Functionality for Contact_SumGoals...

  • need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re,...

    need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re, im; // the real and imaginary parts of a complex number }; typedef struct _cplx Complex; // Initializes a complex number from two real numbers Complex CmplxInit(double re, double im) Complex z = { re, im }; return z; // Prints a complex number to the screen void CmplxPrint(Complex z) // Not printing a newline allows this to be printed in the middle of...

  • Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU...

    Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...

  • #include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc...

    #include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc < 4) { fprintf(stderr, "usage: %s <input file 1> <input file 2> <output file>\n", argv[0]); exit(EXIT_FAILURE); } } /* This function takes in the two input file names (stored in argv) and determines the number of integers in each file. If the two files both have N integers, return N, otherwise return -1. If one or both of the files do not exist, it...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT