Q
Q
Qubc2021-06-09 19:23:51
C++ / C#
Qubc, 2021-06-09 19:23:51

Why is it possible to assign a value to a field of a structural temporary object?

I'm reading Eckel, I'm confused.

struct test {
  int i[10];
};

struct test foo(void) {
  struct test var;
  var.i[0] = 123;
  return var;
}

struct test const fooc(void) {
  struct test var;
  var.i[0] = 123;
  return var;
}

int main(){
  struct test A;

  A = foo();
  A = fooc();

  //! foo() = A; // понятно почему не ок в с и ок в с++ 
  //! fooc() = A;// понятно почему не ок в с и не ок в с++ 

  foo().i[0] = 1; // непонятно почему это ок в с и ок в с++
  fooc().i[0] = 1;// непонятно почему это ок в с
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question