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

5. What is the output of the following C program and explain WHY???? 6. What doe

ID: 3919847 • Letter: 5

Question

5. What is the output of the following C program and explain WHY????

6. What does the following fragment of code do with a linked lists?

7. The below C declaration define 's' to be (choose that applies)

struct node {

int i;

float j; };

a. An array, each element of which is a pointer to a structure of type node.

b. A structure of 2 fields, each field being a pointer to an array of 10 elements.

c. A structure of 3 fields, an integer, a float, and an array of 10 elements.

d. An array, each element of which is a structure of type node.

5. What does the following function do for a given Linked Listst with first node as head?

9. Which of the following is not a disadvantage to the usage of array?

a. Fixed Size

b. You know the size of the array prior to allocation.

c. Insertion based on position

d. Accessing elements at specified positions

10. Point out the error in the following code and explain WHY????

struct emp {

int ecode;

11. Point out the error in the following program?

struct emp {

char n[20];

int age; };

}

Explanation / Answer

5)

Sol) The output is 0.00.

Because, the constant structure elements are defined only two (i.e., integer k value, character c value),but don't defined float f value, in printf statement print the float value (i.e., printf("%.2f",x.f)). Hence, the output display 0.00 value.

6)

Sol) current=head; // head node is assign to current node, then

while(current!=null){ // traversal nodes until null node

current=current.next; // traversing next node next node until null

}

7)

Sol) b is Correct

A Structure of 2 fields, each field being a pointer to an array of 10 elements.

struct node{

int i;

float j;

};

struct node *s[10];

Example: s[0]->i=10 s[0]->j=40.34

5) What does the following function do for a given Linked Lists with first node as head?

void fun1(struct ndoe *head)

{

if(head==NULL) return;

fun1(head->next);

printf("%d",head->data);

}

Sol) Already create Linked Lists elements from head node to NULL.

Here, the function check head node is NULL then return no value, else recursively call fun1() next node then print each element until null.

9) Which of the following is not a disadvantage to the usage of array?

Sol) d) Accessing elements at specified positions

11) Point out the error in the following program?

#include<stdio.h>

int main()

{

struct emp {

char n[20];

int age; };

struct emp e1 = {"David", 23};

struct emp e2 = e1;

// ERROR: invalid check two operands to binary,

// because, we can't use reference(&) operator of structure operands

// we check if(&e1==&e2) is correct

if(e1 == e2)

printf("The structures are equal");

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote