Nested Structures in C - C Programming Tutorial 82

preview_player
Показать описание
Notes for You:: Nested Structures in C - C Programming Tutorial 82
- If required we can place one structure inside another structure; which is called as nesting of structures.
- A structure inside another structure is called embedded structure.

There are two different ways in which we can nest structures:
1. Defining a structure and declaring its variables; completely inside another structure.

Ex:
struct Student
{
int rollnum;
char *name;
struct Date
{
int day;
int month;
int year;
}dateOfBirth;
};

2. Defining a structure independently and declaring its variables inside another structure.

Ex:
struct Date
{
int day;
int month;
int year;
};

struct Student
{
int rollnum;
char *name;
struct Date dateOfBirth;
};

Example Code:
#include <stdio.h>
int main()
{
struct Date
{
int day;
int month;
int year;
};

struct Student
{
int rollnum;
char *name;
struct Date dateOfBirth;
};

struct Student student1 = {10,"Suresh",{1,1,2020}};

// student1 rollnum=10
// student1 name=Suresh
// student1 dateOfBirth=1/1/2020

printf("\n");
// student1 dateOfBirth=2/2/2020
return 0;
}

Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.

=========================================

Follow the link for next video:

Follow the link for previous video:

=========================================

C Programming Tutorials Playlist:

=========================================
Watch My Other Useful Tutorials:-

Computer Programming Fundamentals Playlist:-

C Practical LAB Exercises Playlist:-

C++ Tutorials Playlist:

=========================================

► Subscribe to our YouTube channel:

► Visit our Website:

=========================================
Hash Tags:-
#ChidresTechTutorials #CProgramming #CProgrammingTutorial
Рекомендации по теме
Комментарии
Автор

Answer the following questions: Let's see who gives the best answer
1. Explain structure within structure in C with example ?

ChidresTechTutorials