C-Structure & Union Question and Answer
C-Structure & Union Question and Answer
1. The storage is allocated to structure only when
- structure members are declared
- structure is defined
- structure is called
- structure variable is declared
2. Find the output
struct date
{
int day, month, year;
};
void main ( )
{
struct date today={3, 7, 6, 2007};
printf("%d% d% %d", today. day, today. month, today. year);
}
struct date
{
int day, month, year;
};
void main ( )
{
struct date today={3, 7, 6, 2007};
printf("%d% d% %d", today. day, today. month, today. year);
}
- 3 7 6
- 7 6 2007
- Compilation error
3. Find the output
struct faculty
{
int fid;
int fage;
char fname [20];
}
1ca;
void main ( )
{
static struct dilip={231, 32, "mahesh"};
printf("%d%d%ds", diip.fid);
}
struct faculty
{
int fid;
int fage;
char fname [20];
}
1ca;
void main ( )
{
static struct dilip={231, 32, "mahesh"};
printf("%d%d%ds", diip.fid);
}
- 231 231 32 garbage
- 231 0 0 garbage
- 231 garbage garbage garbage
- Compilation error
4. Find the output
struct emp
{
int age;
char name [20];
float sal;
}
e={23, "bhagya", 8000.000};
void main ( )
{
printf("%d%d%d", e.age, e.name, e.sal);
}
struct emp
{
int age;
char name [20];
float sal;
}
e={23, "bhagya", 8000.000};
void main ( )
{
printf("%d%d%d", e.age, e.name, e.sal);
}
- 23 bhagya 8000.000
- 23 bhagya 8000
- 23 bhagya suffering
- None of these
5. Can the member name of the structure be same as the name of a variable of that structure?
- True
- False
- True, only when structure is self referential structure
- False, only when structuer is self referential structure
6. Find the bug in the following program
1. struct emp{
2. int eid;
3. int age;
4. char n[10];
5. float sal;
6. double eid;
7. struct emp *p;
8. }*q;
1. struct emp{
2. int eid;
3. int age;
4. char n[10];
5. float sal;
6. double eid;
7. struct emp *p;
8. }*q;
- Line no. 7
- Line no. 8
- Line no. 6
- None of these
7. Find the bug in the following program?
1. struct dept {
2. int d;
3. char dname[20];
4. float income;
5. }dn={121,"finance", 20.34};
6. void main ( ) {
7. ++dn. income;
8. printf("%d %s %f", dn.dn,
dn. dname, dn.income);}
1. struct dept {
2. int d;
3. char dname[20];
4. float income;
5. }dn={121,"finance", 20.34};
6. void main ( ) {
7. ++dn. income;
8. printf("%d %s %f", dn.dn,
dn. dname, dn.income);}
- Line no. 5
- Line no. 7
- Line no.8
- None of these
8. Find the output.
structr st
{
int x;
show ( );
}:
struct st s;
show ( )
{
printf ("%d', s.x);
}
void main ( )
{
s.x=10;
s.show();
}
structr st
{
int x;
show ( );
}:
struct st s;
show ( )
{
printf ("%d', s.x);
}
void main ( )
{
s.x=10;
s.show();
}
- 10
- Garbage
- Compilation error
- None of these
9. Find the correct one from the following three compositions
I. typedef struct
{
int month, day, year;
} date;
void main ( )
{
int ano;
date payment;
} record;
record employee[100];
II. typedef struct date
{
int month, day, year;
};
void main ( )
{
int ano;
struct data payment;
}record [100];
record employee;
III. typedef struct
{
int month, day, year;
} date;
void main ( )
{
int ano
data payment;
}
employee [100];
I. typedef struct
{
int month, day, year;
} date;
void main ( )
{
int ano;
date payment;
} record;
record employee[100];
II. typedef struct date
{
int month, day, year;
};
void main ( )
{
int ano;
struct data payment;
}record [100];
record employee;
III. typedef struct
{
int month, day, year;
} date;
void main ( )
{
int ano
data payment;
}
employee [100];
- Only I and II
- Only III
- None of the above
- All of the above
10. Find the output.
typedef struct bitfield
{
int a:7;
char b:8;
unsigned int c:15;
}bit;
void main ( )
{
bit b1;
printf("%d %d %d", sizeof (b1.a),
sizeof (b1.b), sizeof (b1.c);
}
typedef struct bitfield
{
int a:7;
char b:8;
unsigned int c:15;
}bit;
void main ( )
{
bit b1;
printf("%d %d %d", sizeof (b1.a),
sizeof (b1.b), sizeof (b1.c);
}
- 7 8 15
- 2 1 2
- 1 1 2
- Compilation error