Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> सी प्रोग्रामिंग

सी भाषा में नेस्टेड संरचनाएं क्या हैं?

संरचना (या) नेस्टेड संरचनाओं के भीतर संरचना

किसी अन्य संरचना के अंदर की संरचना को नेस्टेड संरचना कहा जाता है।

निम्नलिखित उदाहरण पर विचार करें,

struct emp{
   int eno;
   char ename[30];
   float sal;
   float da;
   float hra;
   float ea;
}e;

भत्ते के अंतर्गत आने वाली सभी वस्तुओं को एक साथ समूहीकृत किया जा सकता है और एक उप-संरचना के तहत घोषित किया जा सकता है जैसा कि नीचे दिखाया गया है।

stuct emp{
   int eno;
   char ename[30];
   float sal;
   struct allowance{
      float da;
      float hra;
      float ea;
   }a;
}e;

एक नेस्टेड संरचना में सबसे आंतरिक सदस्य को डॉट ऑपरेटर का उपयोग करने वाले सदस्य के साथ सभी संबंधित संरचना चर (सबसे बाहरी से सबसे आंतरिक तक) को बदलकर पहुँचा जा सकता है।

कार्यक्रम

निम्नलिखित कार्यक्रम नेस्टेड संरचना (संरचना के भीतर संरचना) प्रदर्शित करना है -

#include<stdio.h>
//Declaring outer and inter structures//
struct Person//Main Structure//{
   char Name[500];
   int Age;
   char Gender;
   char temp;//To clear buffer//
   struct Address//Nested Structure//{
      char Apartment[500];
      char Street[500];
      char City[100];
      char State[100];
      int Zipcode;
   }a[20];//Nested Structure Variable//
   }p[20];//Main Structure Variable//
void main(){
   //Declaring variable for For loop//
   int i;
   //Reading User I/p//
   for (i=1;i<3;i++){//Declaring function to accept 2 people's data//
      printf("Enter the Name of person %d : ",i);
      gets(p[i].Name);
      printf("Enter the Age of person %d : ",i);
      scanf("%d",&p[i].Age);
      scanf("%c",&p[i].temp);//Clearing Buffer//
      printf("Enter the Gender of person %d : ",i);
      scanf("%c",&p[i].Gender);
      scanf("%c",&p[i].temp);//Clearing Buffer//
      printf("Enter the City of person %d : ",i);
      gets(p[i].a[i].City);
      printf("Enter the State of person %d : ",i);
      gets(p[i].a[i].State);
      printf("Enter the Zip Code of person %d : ",i);
      scanf("%d",&p[i].a[i].Zipcode);
      scanf("%c",&p[i].temp);//Clearing Buffer//
   }
   //Printing O/p//
   for (i=1;i<3;i++){
      printf("The Name of person %d is : %s\n",i,p[i].Name);
      printf("The Age of person %d is : %d\n",i,p[i].Age);
      printf("The Gender of person %d is : %c\n",i,p[i].Gender);
      printf("The City of person %d is : %s\n",i,p[i].a[i].City);
      printf("The State of person %d is : %s\n",i,p[i].a[i].State);
      printf("The Zip code of person %d is : %d\n",i,p[i].a[i].Zipcode);
   }
}

आउटपुट

Enter the Name of person 1 : Enter the Age of person 1 : Enter the Gender of person 1 : Enter the City of person 1 : Enter the State of person 1 : Enter the Zip Code of person 1 : Enter the Name of person 2 : Enter the Age of person 2 : Enter the Gender of person 2 : Enter the City of person 2 : Enter the State of person 2 : Enter the Zip Code of person 2 : The Name of person 1 is :
The Age of person 1 is : 0
The Gender of person 1 is :
The City of person 1 is :
The State of person 1 is :
The Zip code of person 1 is : 0
The Name of person 2 is :
The Age of person 2 is : 0
The Gender of person 2 is :
The City of person 2 is :
The State of person 2 is :
The Zip code of person 2 is : 0

  1. सी भाषा में कतार में सम्मिलित करने वाले तत्व क्या हैं?

    डेटा संरचना संरचित तरीके से व्यवस्थित डेटा का संग्रह है। इसे नीचे बताए अनुसार दो प्रकारों में बांटा गया है - रैखिक डेटा संरचना - डेटा को एक रेखीय तरीके से व्यवस्थित किया जाता है। उदाहरण के लिए, सरणियाँ, संरचनाएँ, ढेर, कतारें, लिंक्ड सूचियाँ। गैर-रेखीय डेटा संरचना - डेटा को एक श्रेणीबद्ध तरीके

  1. C लैंग्वेज में शिफ्ट ऑपरेशंस क्या हैं?

    समस्या C भाषा का उपयोग करके किसी संख्या के बाएँ, दाएँ पाली और पूरक को दिखाने का सरल कार्यक्रम क्या है? समाधान बायां शिफ़्ट यदि किसी चर के मान को एक बार बाएँ-शिफ्ट किया जाता है, तो उसका मान दुगना हो जाता है। उदाहरण के लिए, a =10, फिर a<<1 =20 राइट शिफ्ट यदि किसी चर का मान एक बार दायाँ-शिफ्ट किय

  1. C भाषा में प्राथमिक डेटा प्रकार क्या हैं?

    सी कंपाइलर चार मूलभूत डेटा प्रकारों का समर्थन करते हैं। वे इस प्रकार हैं - पूर्णांक चरित्र फ्लोटिंग - पॉइंट डबल सटीक फ़्लोटिंग पॉइंट प्राथमिक डेटा प्रकार अभिन्न डेटा प्रकार इंटीग्रल डेटा टाइप्स का इस्तेमाल पूरे नंबर और कैरेक्टर को स्टोर करने के लिए किया जाता है। इसे आगे दो प्रकारों में वर्गीकृ