C言語のネストされた構造体とは何ですか?
構造内の構造(または)ネストされた構造
別の構造内の構造は、ネストされた構造と呼ばれます。
次の例を考えてみましょう。
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
-
C言語でのシフト演算とは何ですか?
問題 C言語を使用して、数値の左シフト、右シフト、および補数を表示する簡単なプログラムは何ですか? 解決策 左シフト 変数の値が1回左シフトされると、その値は2倍になります。 たとえば、a =10、次にa <<1 =20 右シフト 変数の値を1回右シフトすると、その値は元の値の半分になります。 1 =5 例 以下はシフト操作のCプログラムです- #include<stdio.h> main (){ int a=9; printf("Rightshift of a = %d\n",a&
-
C言語の主要なデータ型は何ですか?
「C」コンパイラは、4つの基本的なデータ型をサポートしています。それらは次のとおりです- 整数 キャラクター 浮動小数点 倍精度浮動小数点 プライマリデータ型 整数データ型 整数データ型は、整数と文字を格納するために使用されます。 さらに2つのタイプに分類されます- 整数データ型。 文字データ型。 整数データ型 このデータ型は、整数を格納するために使用されます。 整数ストレージは、符号付き形式と符号なし形式の両方で、short int、int、およびlongintです。 整数データ型 タイプ サイズ(バイト単位) 範囲 制御文字列 short in(ま