Knowee
Questions
Features
Study Tools

11) List out any 3 differences between malloc and calloc functions in dynamic memory allocation?12) List out any six of the preprocessor directives available in the C programming language?13) Write a C program to pass structure as an argument to the functions using call by value method?14) Write a C program to demonstrate nested structure?15) List out any 3 differences between structure and Unions?

Question

  1. List out any 3 differences between malloc and calloc functions in dynamic memory allocation?12) List out any six of the preprocessor directives available in the C programming language?13) Write a C program to pass structure as an argument to the functions using call by value method?14) Write a C program to demonstrate nested structure?15) List out any 3 differences between structure and Unions?
...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

  1. Differences between malloc and calloc functions in dynamic memory allocation:

a) malloc() allocates a single block of memory, whereas calloc() allocates multiple blocks of memory each of the same size and sets all bytes to zero.

b) The number of arguments differs. malloc() takes one argument: the number of bytes to allocate. calloc() takes two arguments: the number of elements to allocate and the size of each element.

c) malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

  1. Six preprocessor directives available in the C programming language:

a) #include: This directive tells the C preprocessor to include the contents of the file specified in the input stream to the compiler.

b) #define: This directive is used to define a constant or macro.

c) #undef: This directive is used to undefine a constant or macro.

d) #ifdef: This directive checks if a macro is defined.

e) #ifndef: This directive checks if a macro is not defined.

f) #if: This directive checks if a condition is true.

  1. C program to pass structure as an argument to the functions using call by value method:
#include<stdio.h>

struct student {
   char name[20];
   int roll_no;
};

void display(struct student stu);

int main() {
   struct student s;
   strcpy(s.name, "John");
   s.roll_no = 123;
   display(s);
   return 0;
}

void display(struct student stu) {
   printf("Name: %s\n", stu.name);
   printf("Roll No: %d\n", stu.roll_no);
}
  1. C program to demonstrate nested structure:
#include<stdio.h>

struct date {
   int day;
   int month;
   int year;
};

struct student {
   char name[20];
   struct date dob;
};

int main() {
   struct student s;
   strcpy(s.name, "John");
   s.dob.day = 15;
   s.dob.month = 8;
   s.dob.year = 2000;
   printf("Name: %s\n", s.name);
   printf("Date of Birth: %d/%d/%d\n", s.dob.day, s.dob.month, s.dob.year);
   return 0;
}
  1. Differences between structure and Unions:

a) In a structure, all members get memory allocated. In a union, memory is allocated for the largest member only.

b) In a structure, all members can be initialized at once, but in a union, only the first member can be initialized.

c) In a structure, all members can hold their value simultaneously, but in a union, only one member can hold a value at a time.

This problem has been solved

Similar Questions

16) What are Anonymous structures? Give an example.17) List out any 3 differences between static and dynamic memory allocations?18) Write an example program to demonstrate embedded nested structure?19) Write a C program to find the maximum and minimum of two numbers using macros?20) Explain the difference between arrays of structures and arrays within structures?

1) What are Macros? Explain macros with an example program?2) What are structure pointers? .Write a C program that uses structure pointer to refer structure members(attributes) using the arrow (-&gt;) operator?3) Write a C program that uses “array of structures” to store 3(three) “BOOK” records based on“Book_Pages, Book_Price and Book_Name” and to display all the records of 3(three) Books.4) Explain an Array of pointers with syntax and examples.5) Explain about malloc(), calloc() and realloc() with examples? Differentiate between malloc()and calloc().6) What do you mean by conditional compilation in preprocessing directives? Explain with examples.7) Explain the concept of pointers to structures and self referential structure with examples.

11) What is the use of the enum keyword in C?12) What is Structure padding?13) What is the use of the bit field in C?14) What is meant by an anonymous structure?15) What is meant by nested structures?16) What are self referential structures?17) What is the use of #include preprocessor directive?18) What is the use of .(dot) operator?19) What is the use of -&gt;(arrow) operator?20) What is the use of pointer variables in C?

What are the parameters of calloc in C? Marks : 1Negative Marks : 0Answer hereOnly the number of elementsOnly the size of each elementBoth the number of elements and size of each elementThe memory address to allocate

Explain declaration of pointer variables, initialization and accessing a variable through its pointer. Explain how union is declared and how union member is accessed. Explain realloc() and free() function with example. Explain array within structures with example. Explain file opening and closing in C.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.