AFAIK {}
defines a new scope, so what does this define?
({});
The compiler compiles this program well:
#include <iostream>
#include <string>
int main()
{
std::string name;
std::cout << "What is your name? ";
{
({});
}
getline (std::cin, name);
std::cout << "Hello, " << name << "!\n";
}
When i replace ({});
with ();
the complier fails to compile the program.
Why does ({});
work well, but ();
does not?
I have tested the program on cpp.sh. It compiles fine.
%= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to C = C % A.
'#' is called pre-processor directive and the word after '#' is called pre-processor command. Pre-processor is a program which performs before compilation.
In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.
({});
is not part of standard C++. As correctly said by @HolyBlackCat this is compiler extension. Use -pedantic-errors
to disable compiler extensions.
See live demo here when compiled on g++
See live demo here when compiled on vc++
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With