What should main() return in C and C++?

Nitya Raut
Published on 28-Feb-2018 11:02:44
The return value for main is used to indicate how the program exited. If the program execution was normal, a 0 return value is used. Abnormal termination(errors, invalid inputs, segmentation faults, etc.) is usually terminated by a non-zero return. There is no standard for how non-zero codes are interpreted.You can ... Read More

The most elegant way to iterate the words of a C/C++ string

Arjun Thakur
Published on 28-Feb-2018 10:50:29
There is no one elegant way to iterate the words of a C/C++ string. The most readable way could be termed as the most elegant for some while the most performant for others. I've listed 2 methods that you can use to achieve this. First way is using a stringstream ... Read More

What is object slicing in C++ or Java?

Ankitha Reddy
Published on 28-Feb-2018 10:47:26
Object slicing is used to describe the situation when you assign an object of a derived class to an instance of a base class. This causes a loss of methods and member variables for the derived class object. This is termed as information being sliced away. For example, class ... Read More

How can I profile C++ code running in Linux?

Vrundesha Joshi
Published on 28-Feb-2018 10:50:30
There are many great profiling tools for profiling C++ programs on Linux. The most widely used tool is Valgrind. It is a programming tool for memory debugging, memory leak detection, and profiling. You can use valgrind by passing the binary to it and setting the tool to callgrind. First generate ... Read More

What are the rules about using an underscore in a C++ identifier?

Arjun Thakur
Published on 28-Feb-2018 10:41:09
From MSDN docs −Use of two sequential underscore characters ( __ ) at the beginning of an identifier, or a single leading underscore followed by a capital letter, is reserved for C++ implementations in all scopes. You should avoid using one leading underscore followed by a lowercase letter for names ... Read More

Why the use of "using namespace std' considered bad practice?

Abhinaya
Published on 28-Feb-2018 10:33:13
C++ has a standard library that contains common functionality you use in building your applications like containers, algorithms, etc. If names used by these were out in the open, for example, if they defined a queue class globally, you'd never be able to use the same name again without conflicts. ... Read More

Why the use of iostream::eof inside a loop condition considered wrong?

Nancy Den
Published on 28-Feb-2018 10:33:12
Just because we haven't reached the EOF, doesn't mean the next read will succeed.Consider you have a file that you read using file streams in C++. When writing a loop to read the file, if you are checking for stream.eof(), you're basically checking if the file has already reached eof. So ... Read More

What is The Rule of Three with reference to C++?

Govinda Sai
Published on 28-Feb-2018 10:27:33
The Rule of three is a rule of thumb when using C++. This is kind of a good practice rule that says that If your class needs any ofa copy constructor, an assignment operator, or a destructor, defined explicitly, then it is likely to need all three of them.Why is ... Read More

Why can C++ templates only be implemented in the header file?

Ramu Prasad
Published on 28-Feb-2018 10:22:42
When you instantiate a template in C++, the compiler creates a new class. This class has all the places where you placed the template arguments replaced with the actual argument you pass to it when using it. For example −template<typename T> class MyClass {    T foo;    T myMethod(T ... Read More

What is the use of the '&' symbol in C++?

Sravani S
Published on 28-Feb-2018 10:14:06
The & symbol is used as an operator in C++. It is used in 2 different places, one as a bitwise and operator and one as a pointer address of operator.Bitwise ANDThe bitwise AND operator (&) compares each bit of the first operand to that bit of the second operand. ... Read More
Advertisements