logo

Crowdly

Browser

Add to Chrome

Course 31709

Looking for Course 31709 test answers and solutions? Browse our comprehensive collection of verified answers for Course 31709 at lms.aub.edu.lb.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

What is returned by malloc() if the allocation fail?

View this question

#include‹stdio.h›

int main()

{

struct site

{

char name[] = "GeeksQuiz";

int no_of_pages = 200;

};

struct site *ptr;

printf("%d ", ptr->no_of_pages);

printf("%s", ptr->name);

getchar();

return 0;

}

Choose the correct output:

View this question

union test

{

int x;

char arr[8];

int y;

};

int main()

{

printf("%d", sizeof(union test));

return 0;

}

Assume int = 4 bytes, char = 1 byte, no alignment.

View this question

struct node

{

int i;

float j;

};

struct node *s[10];

The above C declaration define 's' to be

View this question

int main()

{

char *s1 = (char *)malloc(50);

char *s2 = (char *)malloc(50);

strcpy(s1, "Geeks");

strcpy(s2, "Quiz");

strcat(s1, s2);

printf("%s", s1);

return 0;

}

Output of following C program? Assume that all necessary header files are included 

View this question

Consider the following C program:

#include <stdio.h>

void fun1(char *s1, char *s2) {

char *temp;

temp = s1;

s1 = s2;

s2 = temp;

}

void fun2(char **s1, char **s2) {

char *temp;

temp = *s1;

*s1 = *s2;

*s2 = temp;

}

int main() {

char *str1 = "Hi", *str2 = "Bye";

fun1(str1, str2);

printf("%s %s", str1, str2);

fun2(&str1, &str2);

printf("%s %s", str1, str2);

return 0;

}

The output of the program above is:

View this question

struct {

short s[5];

union {

float y;

long z;

}u;

} t;

Assume short = 2 bytes, float = 4 bytes, long = 8 bytes.

Ignoring alignment, what is the memory requirement for t?

View this question

Doubly Linked List 

In this exercise you will implement a generic doubly linked list in C. 

Each node in the list contains a pointer to a payload (of type void *), a pointer to the next node, and a pointer to the previous node. 

The list itself keeps track of its head, its tail, and the number of elements currently stored. 

You should write your code in multiple files: 

  • LinkedList.h contains the function prototypes and type definitions. 
  • LinkedList.c contains the functions that you are going to implement. 
  • example_program.c contains the main function that tests the linked list. 

You’ll have to implement the below functions (Note that the LinkedList is Dynamically allocated): 

  • // Allocates and initializes an empty list. Returns a pointer to it. 
    • LinkedList *LL_Create(); 
  • // Frees all nodes in the list. 
    • void LL_Destroy(LinkedList *list) 
  • // Appends a new node with the given payload to the end of the list. Returns 1 on success, 0 on failure. 
    • int LL_Append(LinkedList *list, void *payload); 
  • // Prepends a new node with the given payload to the front of the list. Returns 1 on success, 0 on failure. 
    • int LL_Prepend(LinkedList *list, void *payload); 
  • // Displays the contents of the list. The print_fn callback  is used to print each payload using either printInt or printString. 
    • void LL_Display(const LinkedList *list, void (*print_fn)(void *)); 
  • // Prints a payload assumed to be an integer pointer. 
    • void printInt(void *payload); 
  • // Prints a payload assumed to be a string (char *). 
    • void printString(void *payload); 

To demonstrate how LL_Display can be used, you will provide two printing functions that match the required function pointer type (printInt and printString). These functions can be passed to LL_Display depending on the type of data stored in the list. 

Compile the code on a Linux VM. Show screenshots of the compilation process and run the application (if you weren't able to paste thes screenshots here, send the to our TA Mr Joseph Samara (jfs22)). 

The payloads that will be stored in the linked list are taken as command line arguments. The second command line argument represents the type of data that will be stored in the linked list (either int or string). 

Note that in case of int, the command line arguments must be converted to integers (possibly using the atoi function). 

Examples of running the application 

./app int 33 45 21 89 100 2 

./app string hi hello cmps241 systems programming 

All memory you allocate must be freed.

View this question

#include<stdio.h>

struct st

{

int x;

struct st next;

};

int main()

{

struct st temp;

temp.x = 10;

temp.next = temp;

printf("%d", temp.next.x);

return 0;

}

Choose the correct output from the options given below:

View this question

Consider the following C functions.

int tob (int b, int* arr) {

int i;

for (i = 0; b>0; i++) {

if (b%2) arr [i] = 1;

else arr[i] = 0;

b = b/2;

}

return (i);

}

int pp(int a, int b) {

int arr[20];

int i, tot = 1, ex, len;

ex = a;

len = tob(b, arr);

for (i=0; i<len ; i++) {

if (arr[i] ==1)

tot = tot * ex;

ex= ex*ex;

}

return (tot) ;

}

The value returned by pp(3,4) is ________ .

View this question

Want instant access to all verified answers on lms.aub.edu.lb?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome