Exercise: Structures Unions Enums

Questions for: Structures Unions Enums

Point out the error in the program?
#include<stdio.h>

int main()
{
    struct a
    {
        float category:5;
        char scheme:4;
    };
    printf("size=%d", sizeof(struct a));
    return 0;
}
A:
Error: invalid structure member in printf
B:
Error in this float category:5; statement
C:
No error
D:
None of above
Answer: B

Bit field type must be signed int or unsigned int.

The char type: char scheme:4; is also a valid statement.

Point out the error in the program?
typedef struct data mystruct;
struct data
{
    int x;
    mystruct *b;
};
A:
Error: in structure declaration
B:
Linker Error
C:
No Error
D:
None of above
Answer: C
Here the type name mystruct is known at the point of declaring the structure, as it is already defined.
Point out the error in the program?
struct emp
{
    int ecode;
    struct emp *e;
};
A:
Error: in structure declaration
B:
Linker Error
C:
No Error
D:
None of above
Answer: C
This type of declaration is called as self-referential structure. Here *e is pointer to a struct emp.
What will be the output of the program given below in 16-bit platform ?
#include<stdio.h>

int main()
{
    enum value{VAL1=0, VAL2, VAL3, VAL4, VAL5} var;
    printf("%d\n", sizeof(var));
    return 0;
}
A:
1
B:
2
C:
4
D:
10
Answer: B
No answer description is available. Let's discuss.
What will be the output of the program ?
#include<stdio.h>

    struct course
    {
        int courseno;
        char coursename[25];
    };
int main()
{
    struct course c[] = { {102, "Java"}, 
                          {103, "PHP"}, 
                          {104, "DotNet"}     };

    printf("%d ", c[1].courseno);
    printf("%s\n", (*(c+2)).coursename);
    return 0;
}
A:
103 DotNet
B:
102 Java
C:
103 PHP
D:
104 DotNet
Answer: A
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz