Thursday, September 10, 2015

C++ : My Learnings Part 1



So I picked up one book and is going thru it, since I have already some work experience behind me, I will rather focus more on points which i have came across till now in my work with C.


In this part we will focus on

1) Enum

2) Struct

3) Union

4) Anonymous Union and Enums 

5) Void pointers

6) Scope resolution Operator 

7) Macro (#define) 

8) Typedef 

If we avoid all the tricky questions which can be asked, The basic difference between

TYPEDEF , ENUM , MACRO ( #define)  is that

typedef  has to be used only when you are trying to have a new DATA TYPE. 

ENUM has to be used, when you need to define long list of const , which are in real life. 

Ex : Weekdays , Months , list of student name in class....So even though we can use #define or const int ,  it will be difficult , firstly due to
1) Readability purpose
2) If we need to insert some new variable in list, we have to manual then change the value of each #define

MACRO (#define)  1) Sud not be used as such, since they actually don't anything , but just replace text. So if you can avoid them you should do that. But they can be used when want to better readability or you have to replace a lengthy text with small code

Ex : Suppose if you use lot of for loops in your code .  You can then simply use

#define FOR(start,end)  for(int i=start;i>=0;i--)

In my embedded code , we generally use this with enum to assign function pointers , since the function called will change depending on input.

Also  from MEMORY point of view ,  MACRO don't allocate any space , enum allocate space for just one variable .

Ex :

enum {SUNDAY=0, MONDAY=1)  // total size  will be 4 bytes ; for a machine assigned 4 bytes for int

const int SUNDAY =0;
const int MONDAY =1;

total size will be 8 bytes

#define SUNDAY 0
#define MONDAY 1

no space allocated.

So as can be seen enum is much better than const int , since the space used will be less. I have hardly seen many const in my code , May be const use will be more in OO languages rather than C

Also #define should not be used to assign integer or some other values to some variables, since code can get complex.


TYPEDEF is pretty straightforward, it should be used when you want to give easy name to some new data type which you have created from existing data types.

It also brings us to check the difference between typedef and #define

typedef  int* INT
INT a,b ;
a=&c;
b=&d;


#define INT int*
INT a,b ;
a=&c;
b=&d;

The second one throws error since, #define will simply replace text of INT, and only a will be treated as int* and not b.

In below code

int*   a,b;  or int   *a,b , only  A is pointer and not b.
Same effect happens with #define use.

Anonymous Enum is simply when you just want to use a given variables as CONST, you don't want to assign any value in it.

So don't have to give any type name to enum in that case.


Scope Resolution Operator is ::  and
1) It is available only in C++ and not in C.
2) It is used when their is clash between local and global variable.

Ex :

int a=20;
int main()
{

int a=30;
{
  int a=40;
  printf("%d",::a)
}
}

here ::a will print 20 and not 30 ...it will always take GLOBAL VARIABLE value.


Struct and unions are pretty much self explanatory, if someone has done some C/C++ coding.

So there is no need to go much deep in it. the below program will clear some more doubt.

http://ideone.com/qzt9wU


Void pointers we will cover later once going thru function pointers.


Wednesday, September 2, 2015

MS colleges



http://gregurublog.com/2015/01/13/universities-gre-score-300-to-310/

300-310

  1.  Illinois Institute of Technology – Chicago (Chicago, Illinois)
  2. Tuition Fees : Around 22,000$
Tuition fees : – 15000 $   texas is tax free


Tuition Fee : around 14,000$

Tuition fees : 23, 670 $

Tuition Fees: around 14,000$

12 University of Tampa (Tampa, Florida)

13  University of Houston (Houston, Texas)

http://gregurublog.com/2015/06/17/top-25-university-list-for-gre-score-310-to-320/

Tuesday, September 1, 2015

Courage and Predicament


Is our life better than the animals ?

They roam free, eat what is made available to them , sleep and wakes up at their designated time.

Of course , they have to fight more for their survival than us.  But what is more important FREEDOM or SURVIVAL.

The post is not about what we should do or what not. But mainly how in today's world we are caged and how FEAR has crept in us.

I came from middle class family, I remember when I was young and even till 12th the values of HUMANS EMOTIONS and interaction was given higher importance. They was less FEAR of FAILURE, there was less scrutiny. The student evaluation use to happen only during exams.


Now I am working in COMPANY, the bigger name company you work in and bigger package you get , they less control you have of your own LIFE. The FAILURE becomes exponentially equal to your package.

 Last year , lot of people from my company get laid off. Everyone was sad, when they get bad rating. But afterwards getting new job everyone is more happy.

That's how uncertain and random our life is . We can get sad about something, thinking it as the worst thing happened to us. But in the end we never know and more often than not we end up happy.

Why ...just because we are no longer caged. For my friends who are now working in new company , will definitely again start felling caged after 1-2 years, since FEAR will once again start making its way.

Now this year , they have given me average rating in mid year appraisal, which more seems to make me end up with GOOD rating rather than Very good rating.  ( Our system is quite F*** up)

Now instead of feeling sad , I feel quite relieved,   no pressure is their to maintain the top position.
Now I sit back and relax.

Off course the FEAR of MONEY might came when in MARCH , hike is given. Because of that FEAR I have to prepare and switch company.  Phewwwwwwww

Why we don't get COURAGE to do what we like, WHY when conditions become WORSE , then only we FOLLOW our HEART.

This is my ideal life ........have a nice backpack.....filled with 2-3 pairs of shoes , some dry fruits and chocolates....water and money to refill my stomach and move around from one place to other on foot.

Walk in the desert , have my feet dipped in ocean, feel wind against my face on mountain top ....and climb trees in forest.

A life where MIND no longer is burden thinking about FUTURE and just working out the PRESENT.