Question

#include <stdlib.h> int main() { struct fruit Z; food X = (struct fruit *)malloc(sizeof(struct fruit)); X->taste[4] = (struct

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

#include<stdlib.h>
struct flavour {
   int score;
};
struct fruit {
   struct flavour *taste[5];
   struct fruit *link;
};
typedef struct fruit* food;
int main(){
   struct fruit Z;
   food X=(struct fruit*)malloc(sizeof(struct fruit));
   X->taste[4]=(struct flavour*)malloc(sizeof(struct flavour));
   X->taste[4]->score = 5;
   X->link = &Z;
}
/*
Let's start with variable X, X is storing pointer of structure fruit.
So here food has to be renamed using typedef.
In fruit we are given an array of pointers of structure flavour name taste.
At last fruit structure is having link to itself.
*/

Add a comment
Know the answer?
Add Answer to:
#include <stdlib.h> int main() { struct fruit Z; food X = (struct fruit *)malloc(sizeof(struct fruit)); X->taste[4]...
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
  • C PROGRAMMING #include <stdio.h> #include <stdlib.h> struct nodet { int data; struct nodet *link; }; struct...

    C PROGRAMMING #include <stdio.h> #include <stdlib.h> struct nodet { int data; struct nodet *link; }; struct nodet *makeAnode(int val) { struct nodet *box; box = malloc(sizeof(struct nodet) ); box->data = val; box->link = NULL; return box; } void printList(struct nodet *L) { struct nodet = *mov; mov = L; while(mov != NULL) { printf("%d ", mov->data); mov = mov->link; } printf("\n"); } // THIS SHOULD COUNT HOW MANY ITEMS (NODES) ARE IN THE LIST. int listLen(struct nodet **L) { int...

  • please help, no explanation just need answer #include <stdio.h> #include <stdlib.h> int main(void) { int -x5);...

    please help, no explanation just need answer #include <stdio.h> #include <stdlib.h> int main(void) { int -x5); for (int = 0; i < 5; i++) { x[i] = malloc(sizeof (int) - 5); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { x[i][j] = i j ; modify(x, 5, 5); return 0; Which of the implementations of method modify below set all elements of the matrix x to zero? 1. void...

  • 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...

  • Given the struct xx with the following members: int x-3; char namell-"hello"; What would be the...

    Given the struct xx with the following members: int x-3; char namell-"hello"; What would be the output of the following program? 1. void main) 2. 3. struct xx "s-malloc(sizeof(struct xx)); 4, printf("%d",s->x); 5. printf("%s",s->name); 3 hello Garbage value hello 3 Garbage Value Compiler error None of the above

  • ​what is the output? Consider the following program: #include <stdio.h> #include <stdlib.h> #define size 3 void...

    ​what is the output? Consider the following program: #include <stdio.h> #include <stdlib.h> #define size 3 void func(int **a) {int tmp; for (int i = 0; i < size; i++) {for (int j = i; j < size, j++) {tmp = *(*(a+i)+j); *(*(a+i)+j) = *(*(a+j)+i); *(*(a+j)+i) = tmp;}}} int main() {int **arr = malloc(sizeof(int*) * size); for(int i = 0; i < size; i++) {arr[i] = malloc(sizeof(int) * size); for (int j = 0; j < size, j++) arr[i][j] = 2*i...

  • 1. Select all that are true for the following code. #include <stdio.h> #include <stdlib.h> void range(int...

    1. Select all that are true for the following code. #include <stdio.h> #include <stdlib.h> void range(int start, int end, int *results) { int length = end - start; results = malloc(sizeof(int) * length); for (int i=start; i<end; i++) { *results = i; results++; } } void printArray(int *arr, int length) { for (int i=0; i<length; i++) { printf("%d ", arr[i]); } } int main() { int *x; int s = 2; int e = 11; range(s, e, x); printArray(x, e...

  • #include "stdio.h" #include <iostream> int main() { unsigned char var1 = 4; unsigned short int var2...

    #include "stdio.h" #include <iostream> int main() { unsigned char var1 = 4; unsigned short int var2 = 255; unsigned short int var3 = 16; unsigned int var4 = 1; asm_ MOV AL, var1; MOV AX, var2; MOV AX, var3; MOV EBX, var4; MOVZX ECX, AX; What is the hexadecimal value of BX?

  • Given the following source programs, write down the letter that correspond to the right answer #include...

    Given the following source programs, write down the letter that correspond to the right answer #include <stdio.h> #ifndef MEMORY #include "myhead.h" #include <stdlib.h> myhead.h #include <string.h> int main() { #endif char *text= MEM(SIZE, char); #define SIZE 10 COPY_TEXT (text, MSG); #define MSG "CS262" newtext (text); #define MEM(size, type) SHOW (text); (type *) malloc(size * sizeof(type)) free (text); #define COPY_TEXT (dest, source) return 0; strcpy (dest, source) } text.c #define SHOW (x) printf("Output: %s\n", x) void newtext (char *text) { int...

  • What is the output? #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main()...

    What is the output? #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int x = 5; int y = 2; int z = 30; x = fork(); y = fork(); if (x != 0) printf("Type 1\n"); if (y != 0) printf("Type 2\n"); z = fork(); if (x > 0 || y > 0 || z > 0) printf("Type 3\n"); if (x == 0 && y == 0 && z != 0) printf("Type 4\n"); if (x...

  • ****find_last_node.c #include <stdio.h> #include "linked_list.h" int main(){    ...

    ****find_last_node.c #include <stdio.h> #include "linked_list.h" int main(){       struct node *linked_list = NULL;    linked_list = add_to_list(linked_list, 5, 'a');    linked_list = add_to_list(linked_list, 10, 'b');    linked_list = add_to_list(linked_list, 4, 'c');    linked_list = add_to_list(linked_list, 10, 'd');    linked_list = add_to_list(linked_list, 5, 'e');    linked_list = add_to_list(linked_list, 7, 'f');    linked_list = add_to_list(linked_list, 5, 'g');    linked_list = add_to_list(linked_list, 3, 'h');    int search_number;    printf("Enter number you want to search for:");    scanf("%d", &search_number);    struct node *last_node = find_last(linked_list, search_number);    if (last_node != NULL)    {        printf("Node found: value = %d and...

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