What is auto in c++?

I saw a function auto in the tester’s code in editorial of IMPROVE(Jan LUNCHTIME 2017).

   auto makeMove = [&] (int i) {
	moves.push_back(i);
	assert(p[i] != i);
	assert(p[i+1] != i + 1);
	swap(p[i], p[i+1]);
};

What it is actually? How it works? What is it’s syntax?

Here’s the link to editorial https://discuss.codechef.com/questions/90682/improve-editorial

And tester’s code https://s3.amazonaws.com/codechef_shared/download/Solutions/LTIME44/Tester/IMPROVE.cpp

I don’t use C++ myself so I cant help much, but I sure have found two links which I think might help you!

first
second

I hope it helps!! :slight_smile:

Here is a very nice editorial which will clear all doubts, that is why and where we should use auto data type!. codeforces

And next one is lambda expression that you are asking there! So in this tester solution lambda expression is used to swap the values in vector<>p. We used [&] to capture all external values like moves[], p[] vectors.
after that swap function swap the values here…

If you have doubt about lambda then you can refer here.

  1. Geeks
  2. Cppreference

Feel free to ask again if you have still doubt!

1 Like

jerry coffin explained it in a simplified manner while answering on stackoverflow …here is the link

auto

1 Like

Thanks @bansal1232

Auto means the increment operation will automatically works. I think this is the simple term you can understand easily. As you know there are increment and decrements operation you can use easily.

Flowers online Dubai | Online flower delivery Dubai | Send flowers Dubai

Please @Admin delete the account of @samihahkassis. This guy is spamming here and unnecessary advertising their products!

1 Like

@admins, checking @samhahkassis 's previous posts, we all can clearly see that he is spamming/advertising here. His previous answers are a big proof, please look to it, as @bansal1232 said. (I mean, since we got proofs, it shouldn’t be hard to ban him. )