Posts

What is Code Bloat?

Code bloat refers to the unnecessarily generated code which effects the performance of the program. It makes program run slow and uses unncessary resources. Example for code bloat is using in-line functions for long peice of code. Some naive compilers of C++ will make different function of each type if a template is defined, which causes so much of unnecessary code which is never executed. This un used code is called as dead code.
What is Aggregation? Aggregation means creating an object out of another object.

GCC Extenstion

GCC has given some additions to its existing functionality. Please find more details from the below link. http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/index.html

About Random numbers!

How to generate Random numbers? We can generate Random numbers by using rand() or random() function. This is defined in "stdlib.h". Example below illustrates to generate Random number. #include < stdio.h > #include < stdlib.h > int main() {     int i;     int num;     int range;          num = random();  // or else use rand()     printf("\nnum : %d", num);     num = random(); // or else use rand()     printf("\nnum : %d", num);          return 0; } But everytime you run this program, it will give same series. Starting number is decided by the seed, which is always initialized by 0 for rand(). If we want a different series, we need to initiate seed value using srand(int). That means, for a particular seed value, we always get one series. srand(int); Good way of initiating seed value is by using time, so that everytime we get different value for seed. See the example below: #include < stdio.h > #include < stdlib.h > #include < tim

What is Code Bloat?

Code bloat refers to the unnecessarily generated code which effects the performance of the program. It makes program run slow and uses unncessary resources. Example for code bloat is using in-line functions for long peice of code. Some naive compilers of C++ will make different function of each type if a template is defined, which causes so much of unnecessary code which is never executed. This un used code is called as dead code.

Difference between class & struct?

There is only one difference betweeen a class & struct i.e., struct is by default public and class is private.

Method Chaining.

ob.fun1().fun2(): This way of calling functions is called Method Chaining. I have seen this using in big projects quite often. Here 1st ob.fun1() will be called which will return the some object. Then this object's fun2() will be called. The below example is to illustrate the Method Chaining. Eg: ================================================================= class A {     int x;     public:         A() {x=10; }         int getX() { return x;} }; class B {     int y;     public:         B() { y=20; }         A fun2(); }; A B::fun2() {     A o;     return o; } int main() {     A ob;     B ob2;     cout<<  ob2.fun2().getX() ;    return 0; } ================================================================= Output: 10