How many ways are there to initialize an int with a constant?
Answer Posted / nikhil upadhyay
Two.
There are two formats for initializers in C++ as shown in the example that follows. The first format uses the traditional C notation. The second format uses constructor notation.
int foo = 123;
int bar (123);
It's acceptable when a programmer does not know about the second notation, although they should certainly know about the first one. Many old-timer C programmers who made the switch to C++ never use the second idiom, although some wise heads of C++ profess to prefer it. If your applicant is quick with the right answer, that's a good sign.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which coding certification is best?
How delete [] is different from delete?
Explain terminate() and unexpected() function?
Can we use this pointer in a class specific, operator-overloading function for new operator?
Explain the virtual inheritance in c++.
What is the best free c++ compiler for windows?
What problems might the following macro bring to the application?
Is c++ still being used?
What is the difference between prefix and postfix versions of operator++()?
Can we sort map in c++?
Mention the purpose of istream class?
What is vector string in c++?
Can comments be longer than one line?
Which software is used for c++ programming?
What is increment operator in c++?