Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Why this code yield different result in C++14 and C++17?

Правка en1, от WeZoomIn, 2019-10-02 16:47:18

I'm using Codeforces custom test. When compile and run, this code yield different results,

#include <bits/stdc++.h>
using namespace std;

int k;
map<int,int> a[2];
int bar () {
	return ++k;
}
void foo () {
	a[k][1] = bar();

}
int main() {
	k=0;
	foo ();
	cout<<a[0][1]<<" "<<a[1][1]<<endl;
	return 0;
}

//GNU G++11, GNU G++14 yield "1 0"
//GNU G++17 yield "0 1"

Is there any issue about this? What is expected behavior is this case?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский WeZoomIn 2019-10-02 16:47:18 536 Initial revision (published)