Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C PROGRAM: 1. Create three of your own structures definitions. 2. Identify eithe

ID: 3675569 • Letter: C

Question

C PROGRAM:

1. Create three of your own structures definitions.

2. Identify either one similarity or one difference between an array and a structure.

3. Looking at the partial program code below, how could you determine if the functions printf(), sqrt() and doubl() were user defined functions or from the C Standard Library. Assume the program is complete, compiles and runs correctly. Each student is to provide one unique method for determination.

int main(void)
{
      int x = 4;
      printf("Square root = %f twice x = %f", sqrt(x), doubl(x) );
      return 0;
}

Explanation / Answer

1.

In the C language structures are used to group together different types of variables under the same name. For example you could create a structure “telephone”: which is made up of a string (that is used to hold the name of the person) and an integer (that is used to hold the telephone number).
Take a look at the example:

With the declaration of the structure you have created a new type, called telephone. Before you can use the type telephone you have to create a variable of the type telephone. Take a look at the following example:

To access the members of the structure telephone, you must use a dot between the structure name and the variable name(variables:name or number.) Take a look at the next example:

2.

1.Array is a group of homogeneous elements because all elements in an array belongs same data type.

2. Structure is a group of heterogeneous elements.

3. Array allocates static memory and uses index / subscript for accessing elements of the array.

4. Structures allocate dynamic memory and uses (.) operator for accessing the member of a structure.

5. Array is a pointer to the first element of it. Structure is not a pointer.

6. Array element access takes less time in comparison with structures.

3.

#include<studio.h>

#include<math.h>

int main(void)
{
      int x = 4;
      printf("Square root = %f twice x = %f", sqrt(x), (2*x) );

      return 0;
}

Note: There is no doubl() function in c language. If we want to perform double of the variable just write 2*variable value.