070 sizeof 运算符

#include <stdio.h>
#include <stdlib.h>

struct student {
    char gender;    // F or M
    unsigned short age;
    int vote;
};

void counting(struct student voters[3], size_t num)
{
    int count = 0, i;
    
    printf("sizeof void*: %ld\n",
        sizeof(void*));
    printf("sizeof array function parameter voters: %ld\n",
        sizeof(voters));
    
    for (i = 0; i < num; i++)
        if (voters[i].vote) count++;

    printf("totally %d students vote\n", count);
}

int main(int argc, char *argv[])
{
    size_t num;
    struct student voters[3];

    printf("sizeof char: %ld\n", sizeof(char));
    printf("sizeof unsigned short: %ld\n", sizeof(unsigned short));
    printf("sizeof int: %ld\n", sizeof(int));
    printf("sizeof struct student: %ld\n", sizeof(struct student));
    printf("sizeof voters array: %ld\n", sizeof(voters));
    num = sizeof(voters)/sizeof(voters[0]);
    printf("totally %ld voters\n", num);

    voters[0].gender = 'F';
    voters[0].age = 20; 
    voters[0].vote = 1;
    voters[1].gender = 'M';
    voters[1].age = 21; 
    voters[1].vote = 1;
    voters[2].gender = 'M';
    voters[2].age = 20; 
    voters[2].vote = 0;

    counting(voters, num);
    return 0;
}