1.f) What are Nested Structures? Give an example.
2
Ans: Nested structures are structures as member of another structure. For example,the date of birth is astructure within the structure of a student as shown below. These types of structures are known as nested structures.
Eg1:
struct date
{ int dd;
int mm;
int yy;
};
struct student
{ char name[20];
int roll;
date dob;
int marks; };
The member of a nested structure is referenced from the outermost to innermost with the help of dot operators. student stud; Then the members of the nested structure can be accessed as stud.dob.mm=10;
Eg2:
struct addr
{ int houseno;
char area[26];
char city[26];
char state[26];
};
struct emp
{ int empno;
char name[26];
char design[16];
addr address;
float basic;
};emp worker;
2006 Outside Delhi:
1.C) Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.
2
#include<iostream.h>
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost=100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}
Ans:
#include<iostream.h>
#include<stdio.h>
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost;
//Initialization of variables inside a structure is not allowed.
}MOVIE;
gets(MOVIE.movie_name);
cin>>MOVIE.movie_type;
//A single character cannot be read using gets}
CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )