Open In App

Code Bloating in C++ with Examples

Code bloat is the production of code that is perceived as unnecessarily long, slow, or otherwise wasteful of resources. It is a problem in Software Development which makes the length of the code of software long unnecessarily. So for writing the quality code, we always avoid code bloating in our program.

Following are some reasons for the Code Bloating:



Program:




#include <iostream>
using namespace std;
  
// Driver Code
int main()
{
    // Code Bloating
    string str("GeeksForGeeks");
  
    // Print string str
    cout << str << endl;
    return 0;
}

Output:
GeeksForGeeks

The above program will work perfectly and will print GeeksForGeeks. But there is a problem of code bloating in above program in first line of main function. The agenda of above program is to print the string GeeksForGeeks, So why we are creating object of string class as it result in creating string class object.
We simply could write

cout << "GeeksForGeeks" << endl; 

Effects of Code Bloat:


Article Tags :