Struct, union, enum

1. What is output?

#include <stdio.h>
#include <conio.h>

typedef struct 
{
    char c; // 1 byte
    float b; // 4 byte
    int a;   // 4 byte
}A; 

void main()
{
    printf("\n Size of struct: %d", sizeof(A));
    getch();
}

Giả sử dùng VC++ 2008 trên hệ điều hành 32 bit
A. 9
B. 12
C. 16
D. 24
Đáp án

B

2. What is output?

#include <stdio.h>
#include <conio.h>

typedef struct 
{
    int a[2];   // 8 byte
    char b[5]; // 5 byte
    char c[5]; // 5 byte
    
}A; 

void main()
{
    printf("\n Size of struct: %d",sizeof(A));
    getch();
}

A. 20
B. 18
C. 32
D. 24
Đáp án

A

 

3. What is output?

#include <stdio.h>
#include <conio.h>

struct birthday 
{
    int d; // day
    int m; // month
    int y; // year
};
struct info
{
    int ID; // code of staff
    birthday b;   
};

void main()
{
    info a = {1009, 16, 9, 1989};
    printf("\nID=%d, dd/mm/yyyy = %d/%d/%d", a.ID, a.b.d, a.b.m, a.b.y);
    getch();
}

A. ID=1009, dd/mm/yyyy = 16/09/1989
B. ID = 1009, dd/mm/yyyy = garbage value/garbage value/garbage value (garbage value: giá trị rác)
C. Error sytax (Lỗi cú pháp)
Đáp án

A

 

4. What is output?

#include <stdio.h>
#include <conio.h>

void main()
{
    struct site
    {
        char name[] = "vncoding";
        int year = 2;
    };
    struct site *ptr;
    printf("%s ", ptr->name);
    printf("%d", ptr->year);
   
    getch();
}

A. vncoding 2
B. Complier error
C. Runtime error
Đáp án

B

Chỉ có member static của struct mới được phép khởi tạo bên trong struct

5. What is output?

#include <stdio.h>
#include <conio.h>

typedef struct
{
    int x;
    static int y;
}st;

void main()
{
    printf("sizeof(st) = %d", sizeof(st));
    getch();
}

A. 4
B. Complier error
C. 8
Đáp án

A

6. What is output?

#include <stdio.h>
#include <conio.h>

struct 
{ 
    short s[5];
    union 
    { 
        float y; 
        long z; 
    }u; 
} t;

void main()
{
    printf("sizeof(st) = %d", sizeof(t));
    getch();
}

A. 16
B. 22
C. 32
D. 18
Đáp án

A

 

7. Which of the following operators can be applied on structure variables?
A. Equality comparison ( == )
B. Assignment ( = )
C. Both of the above
D. None of the above
Đáp án

D

Be the first to comment

Leave a Reply