Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to assign fixed size array?

Tags:

c

struct

in C , i have

struct a {
    int a;
    char b[16];
    int c;
};

How is the memory of instances of struct a, will it be flat with the struct area, or inside struct a there are pointer, for example , will the struct sizeof be 4+16+4 , or 4+4+4 ?

what will happen if i have

struct a A,B;
A->b = B->b;

?

like image 770
shd Avatar asked Dec 21 '22 09:12

shd


1 Answers

how is the memory of instances of struct a, will it be flat with the struct area, or inside struct a there are pointer

Flat.

The array member is a real array, the size of the struct will be

2*sizeof(int) + 16 (+ padding)

what will happen if i have struct a A,B A->b = B->b

A compilation error. Arrays are not assignable.

like image 164
Daniel Fischer Avatar answered Dec 24 '22 01:12

Daniel Fischer