Which of these are valid declarations?

(i) union {

Loading

Practice Structures, Unions, Enums – Which of these are valid declarations?

(i) union {
int i;
int j;
};

(ii) union u_tag {
int i;
int j;
};

(iii) union {
int i;
int j;
FILE k;
};

(iv) union {
int i;
int j;
}u;

The following statement is

“The size of a struct is alway

Loading

Practice Structures, Unions, Enums – The following statement is

“The size of a struct is always equal to the sum of the sizes of its members”

Structure can be used

Loading

Practice Structures, Unions, Enums – Structure can be used

Consider the following declarations.


Loading

Practice Structures, Unions, Enums – Consider the following declarations.


union id {

char color;

int size;

}

struct {

char country;

int date;

union id;

} flag;


To assign a color to a fag, the correct statement would be

A short integer occupies 2 bytes, an ordinary integer 4 bytes and a lo

Loading

Practice Structures, Unions, Enums – A short integer occupies 2 bytes, an ordinary integer 4 bytes and a long integer occupies 8 bytes of memory.

A structure is defined as


struct TAB {

short a;

int b;

long c;

} TABLE [10];


Then the total memory requirement for TABLE is

If an integer occupies 4 bytes and a character occupies 1 byte of memo

Loading

Practice Structures, Unions, Enums – If an integer occupies 4 bytes and a character occupies 1 byte of memory, each element of the following structure would occupy how many bytes?


struct name {

int age;

char name[20];

}

Consider the following definitions


			  		

Loading

Practice Structures, Unions, Enums – Consider the following definitions



struct circle {

float radius;

struct point centre;

} circle cl;



struct point {

int x;

int y;

}


One can define a circle by the following assignment statement

What will be output of the following “c” code?


Loading

Practice Structures, Unions, Enums – What will be output of the following “c” code?


#include

enum color{BLACK, BLUR, GREEN};

void main()

{

printf("%d %d %d", BLACK, BLUR, GREEN);

}

What will be the size of these structures?

			  		

Loading

Practice Structures, Unions, Enums – What will be the size of these structures?


#include
struct S1 {
char c;
int i[2];
double v;
} SA1;
struct S2 {
double x;
int i[2];
char c;
} SA2;
int main()
{
printf("
sizeof S1 %d : Sizeof S2 %d ",sizeof(SA1),sizeof(SA2));
return 0;
}

Note:char takes 1 byte, int takes 4 bytes, double takes 8 bytes

What is the output of the following problem ?

			  		

Loading

Practice Structures, Unions, Enums – What is the output of the following problem ?


#include

struct {
int x;
int y;
union {
int id_no;
char *name;
}b;
}s,*st;
int main()
{
st = &s;
st->x=10;
st->b.id_no = 101;
printf("%d %d
",s.x,s.b.id_no);
return 0;
}

What will be the output of the following program on GCC compiler ?<

Loading

Practice Structures, Unions, Enums –

What will be the output of the following program on GCC compiler ?

#include<stdio.h>  
int main() {
union var {
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d ", v.a);
return 0;
}

Point out the error in the following program in GCC compiler?

Loading

Practice Structures, Unions, Enums –

Point out the error in the following program in GCC compiler?

#include<stdio.h>  
int main() {
struct emp {
char name[25];
int age;
};
struct emp e;
e.name = "Suresh";
e.age = 25;
printf("%s %d ", e.name, e.age);
return 0;
}

Point out the error in the following program on GCC compiler?

Loading

Practice Structures, Unions, Enums –

Point out the error in the following program on GCC compiler?

#include<stdio.h> 
int main() {
struct bits {
float f:2;
}bit;
printf("%d ", sizeof(bit));
return 0;
}