In the C programming language, the keyword 'int' is used in a type declaration to give a variable an integer type.
Int, short for "integer," is a fundamental variable type built into the compiler and used to define numeric variables holding whole numbers. Other data types include float and double. C, C++, C# and many other programming languages recognize int as a data type.
int a1{b}; So technically there are no constructors for basic-POD types. But for all intents and purposes they act just like they have a copy constructor and default constructor (when initialized with the braces). If it looks like a duck and quacks like a duck, then its very duck like.
Please read the question entirely before you think to mark it as duplicate. The statement like
int i=int();
most programmers will say that there is value initialization here & i
will be value initialized. (0 as output). But it also prints 0 as output on C++98 compiler.
Following program that I tested on C++98 implementation and gives me 0 as output.
#include <iostream>
int main()
{
int i=int();
std::cout<<i;
}
Don't say that i is value initialized in above C++98 program ,because value initialization introduced in C++03. So How i is initialized here? Is it really constructor call? int() looks like constructor call. Primitive types have also default constructors in C++ as said by Bjarne stroustrup in his book C++ programming language & TC++PL.
The C++ programming language Bjarne stroustrup:
10.4.2 Built in types also have default constructors
also read section 6.2.8 of same book.
The following links also says that built in types have default constructors in C++.
1) http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=15
2) http://www.geeksforgeeks.org/c-default-constructor-built-in-types/
So can I really say that it is a constructor call of the integer type?
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