senin yardımını bekliyor. Cevapla
Mintik'e katıl

"Giriş yaparak Mintik'in Hizmet Şartlarını kabul ettiğinizi ve Gizlilik Politikasının geçerli olduğunu onayladığınızı kabul etmiş olursunuz."

  1. True. In C, only one member of a union can be accessed with a valid value at a particular time.

    Here’s why:

    Shared Memory: Unions allocate a single block of memory to store all its members. This memory size is determined by the largest member type.

    Overwriting Values: Because all members share the same memory location, accessing a new member overwrites the value of the previously accessed member.

    Trying to access multiple members simultaneously can lead to undefined behavior, meaning the program’s outcome becomes unpredictable.

    • Here’s an example:

      C

      union Data {
        int num;
        float decimal;
        char str[10];
      };
      
      int main() {
        union Data data;
      
        data.num = 10; // Assigns 10 to the shared memory
        printf("Integer: %d\n", data.num);  // Valid access, prints 10
      
        data.decimal = 3.14; // Overwrites the memory with the decimal value
        printf("Float: %f\n", data.num);  // Undefined behavior, might print 3.14 or something else
      }
Bu soruları yanıtlayarak arkadaşlarınıza yardım edin