Knowee
Questions
Features
Study Tools

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?

Question

  1. 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?
🧐 Not the exact question you are looking for?Go ask a question

Solution

  1. Anonymous structures are a feature of C programming language that allows the declaration of a structure without a name. These structures are useful when you want to use a structure only once in your program.

Example:

struct {
   int a;
   float b;
} x;
x.a = 10;
x.b = 20.5;
  1. Differences between static and dynamic memory allocations:
  • Static memory allocation is done at compile time while dynamic memory allocation is done at runtime.
  • In static memory allocation, memory size is fixed while in dynamic memory allocation, memory size can be changed according to the needs at runtime.
  • Static memory allocation can cause memory wastage if allocated memory is not fully utilized. In dynamic memory allocation, memory is used efficiently as it is allocated as per requirements.
  1. Example program to demonstrate embedded nested structure:
#include<stdio.h>
struct date {
   int day;
   int month;
   int year;
};
struct employee {
   char name[20];
   struct date join_date;
};
int main() {
   struct employee emp;
   printf("\nEnter name: ");
   scanf("%s",emp.name);
   printf("\nEnter join date (dd mm yyyy): ");
   scanf("%d %d %d",&emp.join_date.day,&emp.join_date.month,&emp.join_date.year);
   printf("\nEmployee Details: ");
   printf("\nName: %s",emp.name);
   printf("\nJoin Date: %d/%d/%d",emp.join_date.day,emp.join_date.month,emp.join_date.year);
   return 0;
}
  1. C program to find the maximum and minimum of two numbers using macros:
#include<stdio.h>
#define MAX(a,b) ((a>b)?a:b)
#define MIN(a,b) ((a<b)?a:b)
int main() {
   int num1, num2, max, min;
   printf("\nEnter two numbers: ");
   scanf("%d %d",&num1,&num2);
   max = MAX(num1,num2);
   min = MIN(num1,num2);
   printf("\nMaximum: %d",max);
   printf("\nMinimum: %d",min);
   return 0;
}
  1. Difference between arrays of structures and arrays within structures:
  • An array of structures is a collection of structure variables where each variable contains information about different entities. For example, an array of a structure 'student' can store information about multiple students.
  • An array within a structure is a structure where one or more members are arrays. This is useful when you want to store multiple values of the same type that belong to a single entity. For example, a structure 'student' can have an array to store marks in different subjects for a single student.

This problem has been solved

Similar Questions

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?

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?

6) Explain about macros with an example.7) Explain about Bit fields with examples.8) What is an enumeration? Give an example for enumeration.9) What are self-referential structures? Write the syntax for the same.10) Write a C program to demonstrate Enumeration type?

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.

1) Explain the use of typedef keyword and #define preprocessor directive.2) How to include user defined header files into your program? Give an example.3) What are the situations where a pointer becomes a dangling pointer? Explain with an example.4) Explain the enum with an example.5) Explain about Nested Structures with examples?

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.