Question

Consider the two variables in the following C-like (not C) code. Assume that both types of...

  1. Consider the two variables in the following C-like (not C) code. Assume that both types of long and int use 32 bits. Do the variable a and b have equivalent type under name type equivalence? What if under structure type equivalence? 0

    struct {char c1[4],c1; int i;} a; struct {char c1[2],c2[3]; long l;} b;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Before we jump in, you should know what name and structure equivalence are.
Name equivalence: According to name equialence, two data types are equivalent if the have the same name.
For example:
Let us consider two struct definitions given by you.
struct
{
   char c1[4],c1;
   int i;
}a, c;

struct
{
   char c1[2],c2[3];
   long l;
}b, d;

Here a can be equal to c but not b or d.
Structure equivalence: According to structure equivalence, two data types are equivalent if they have the same structure definition.
Again a and c can be equal because their definitions are one and the same but a and b cannot be equal because their definitions are different.
Here, by definition, I refer to the data members in the struct.

Add a comment
Know the answer?
Add Answer to:
Consider the two variables in the following C-like (not C) code. Assume that both types of...
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
  • 2.(25pts) For the following code specify which of the variables a,b,c,d are type equivalent under (a)...

    2.(25pts) For the following code specify which of the variables a,b,c,d are type equivalent under (a) structural equivalence, (b) strict name equivalence, and (c) loose name equivalence. Type   T = array [1..10] of integer S = T a: T b: T c: S d: array [1..10] of integer

  • // C code // If you modify any of the given code, the return types, or...

    // C code // If you modify any of the given code, the return types, or the parameters, you risk getting compile error. // Yyou are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable: 4996) // for Visual Studio #define MAX_NAME 30 // global linked list 'list' contains the list of patients struct patientList {    struct patient *patient;    struct patientList *next; } *list = NULL;  ...

  • 2. Give the minimum size of each of the following C++ types, assuming that char values occupy one...

    2. Give the minimum size of each of the following C++ types, assuming that char values occupy one byte, short values occupy two bytes, int and float values occupy four bytes, double and long values occupy eight bytes, and pointers occupy four bytes. a) union u type ( double a[3]; int *b; char c[10] b) struct s1type float *d [2]; long e[4] char f[6] short *gi c) struct s2 type ( s1_type s; u type u [2]; int *h[3]; short...

  • The following C code defines a structure for student and then creates a student structure type...

    The following C code defines a structure for student and then creates a student structure type variable by setting the no as 8 and name as "Demo". One statement is missing in this C code. Please select one statement from the following options to make this program work. s ions s saved Status include <stdio.h> include <string. h struct student int no; char name void main struct student s; S. no 8 print f("Ed 8s In", s. no, s. name)...

  • URGENT. Need help editing some C code. I have done most of the code it just...

    URGENT. Need help editing some C code. I have done most of the code it just needs the following added: takes an input file name from the command line; opens that file if possible; declares a C struct with three variables; these will have data types that correspond to the data types read from the file (i.e. string, int, float); declares an array of C structs (i.e. the same struct type declared in point c); reads a record from the...

  • Prints out the size of (there’s a hint, by the way) variables with the following C...

    Prints out the size of (there’s a hint, by the way) variables with the following C data types – int, long, unsigned, long long, char, float and double. This is how many bytes of memory a variable of that type occupies on this machine, using your chosen compiler. (Xcode) Answer the following question: Does adding the static keyword to the declaration of these variables in your program change their size? Answer the following question: What is the largest number and...

  • help 9. Consider the following code segment: Struct some Int a: Long bi Char c Void foo (struct some s) S.a -21 s.b 1989: Int main0 Struct some thing: Foo (thing) Label the following stack diagra...

    help 9. Consider the following code segment: Struct some Int a: Long bi Char c Void foo (struct some s) S.a -21 s.b 1989: Int main0 Struct some thing: Foo (thing) Label the following stack diagram-from the perspective of function foo-each field of the struct should be clearly marked. Assume 8 byte wide words. 0x060 0x068 0x070 0x078 0x080 Ox088 Ox090 0x098 0x100 Ox108 Old base pointer Return address 9. Consider the following code segment: Struct some Int a: Long...

  • Canvas → XC D Question 13 Given the code below: typedef struct p { char topic...

    Canvas → XC D Question 13 Given the code below: typedef struct p { char topic [20]; int nunWords; > page; typedef struct mag char name[20]; page pages [250); int numPages; } magazine; magazine m; How would you declare an array of 20 magazines? struct magazine[20] magazine[20] magazine myStack(20) None of the above struct m[191 Question 14 Given the code below: typedef struct char topic[20] Canvas & XC struct m[19] Question 14 Given the code below: typedef struct char topic[20];...

  • 2) Write an assembly program that is algorithmically equivalent to the following C+t code Consider the variables to be 8-bit unsigned integers; you may initialize them to any values 0-255 if you like...

    2) Write an assembly program that is algorithmically equivalent to the following C+t code Consider the variables to be 8-bit unsigned integers; you may initialize them to any values 0-255 if you like for testing purposes 13 int speed, lower, a, b; 14 15 if (speed < 98) { 16 17 if (speed <80) t 18 lower++; 19 20 21 else f 23 24 25 26 else t 27 28 2) Write an assembly program that is algorithmically equivalent to...

  • C language not C++ 1. Write the statements to do the following: (2 pts) a. Define...

    C language not C++ 1. Write the statements to do the following: (2 pts) a. Define a struct with member variables width, height, topleft x, topleft y all floats). Use a tag to call it Rectangle. b. Declare a variable struct type Rectangle 2. Consider the following variables: struct int x; float y; char zi var1; union nt x; float y; char[20] z;) var2 f float and int are stored using 4 bytes each, what is the size (in bytes)...

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