Thursday 28 January 2016

Pointer in C - Made Easy - Part 01





What are Pointers?


Did you ask anyone what is the most difficult thing to learn in C. I can bet, 95% of the learners will say, "Huh, it is Pointers". Agreed ?
The only thing why we feel it because C uses the pointers extensively, but believe me, the concept of the pointers is very simple. The only problem is, its terminology, e.g. use of & and * and we get confused where to use what? Am I Right?

So Let's make it easy for us.

So do you know what a variable is? If you know what a variable is, then you know already, what a pointer is? I am not joking.

Variable: A variable for us is just a name which holds a value. Variable can change the value in a program, that's why it is called a variable.


    int sum;


It tells us that sum is a variable which holds an integer value.
But how it is happening in our computer.


Well, its all happening in memory of the computer. You can visualize the computer memory like below:


Address:   :


              |-----|
  0x1100|       |   sum is an integer, one machine word big
              |-----|
      
              |-----|
  0x1104|       |   ptr is a pointer, also one word big
              |-----|
           :
Don't get confused with "One machine word big". It means it depends on computer. In my case, One word means 4 bytes, so it is taking 4 memory space (1100 to 1103), each of one Byte.


So what we understood by:


  
 int sum;


sum is a variable which holds an integer


               OR
sum is a memory location in the computer and that memory location holds an integer.


so the above statement (int sum;) is telling the computer to reserve a memory location (when the program will execute) which will hold an integer.


Lets talk about the pointer now.


   int *ptr;


This statement tells the computer that ptr is not a normal variable like sum in above example. Rather it is a pointer variable. A pointer variable always hold a memory address which is always a number.


What about the keyword int here.


So, above statements tell that ptr is a pointer variable (which holds a memory address) and it points to an integer. It means the memory address it is holding will be the memory address of an integer.


Lets make it simpler:


In the above example, Memory address 0x1100 is holding a variable sum.


ptr is a pointer variable which points to an integer, so it can point to sum. Right?


so if ptr want to point to sum, it should hold the Memory address of sum. This means it should hold 0x1100. Now assume that sum is 21


So,


   int sum=21;
   int *ptr;



Above two statements will look like below in memory


               |---- -|
  0x1100 |  21  |   sum
               |------|




               |------|
  0x1104 |        |   ptr is a pointer
               |----- |


Now if we want that ptr should hold the memory address of sum (which is an integer), how it will look in memory:

               |---- -|
  0x1100 |  21  |   sum
               |------|


               |----- |
  0x1104 |0x1100|   ptr is a pointer, also one word big
               |----- |


 All right ! You got it.


Now how to write it in code?


    int sum=21;
    int *ptr;
    ptr = ∑


First two statements, we know. In third statement, we are assigning the address of sum (using & operator) into ptr. Since ptr can hold the address only that why we assigned it an address, not the value.


Did you recall something? You have used the pointer already, but you don't know it. Remember scanf statement when you used to read the value of a variable using the & operator. You were doing nothing but reading the memory location. Make sense?


Now ptr is an address right? So what is the value at that address. You will say 21 right i.e. the value of sum. So you can directly print the value of sum in your printf statement. But can you tell the value at that address in terms of ptr. Yes, you can say it is *ptr


So what did we learn?


ptr is a pointer which is holding a memory location. sum is a variable. Address of sum is &sum.


This address we have stored in a pointer called ptr. So ptr is also a memory address of sum means &sum and ptr is sum.


Value at the address represented by ptr is *ptr which is 21.


Think about the below statements:
        printf("sum is %d.\n", sum);
        printf("sum is %d.\n", *ptr);
and
        printf("sum is located at %x.\n", &sum);
        printf("sum is located at $%x.\n", ptr);



Wednesday 27 January 2016

Difference between vSphere, ESXi and vCenter - Simplified



VMware Inc. is a software company that develops many suite of software products specially for providing various virtualization solutions.

Virtualization means you are using a big physical computer and running so many computers (Operating systems) simultaneously in it virtually. This machine should be of appropriate capacity in terms of Hard Drive, Memory, Processor etc. The Operating systems running under this big computers are called guest OS

vSphere: vSphere is a software suite that comes under Data Center product. vSphere is like Microsoft Office suite which has many software like MS Office, MS Excel, MS Access and so on. Like Microsoft Office, vSphere is also a software suite that has many software components like vCenter, ESXi, vSphere client and so on. So, the combination of all these software components is vSphere. vSphere is not a particular software that you can install and use. Mark it, vSphere is group (package) of software. Got it?

ESXi, vSphere client and vCenter are components of vSphere.

ESXi: ESXi server is the most important part of vSphere. ESXi is the Virtualization Server.  All the virtual machines or Guest OS are installed on ESXi server. To install, manage and access those virtual servers which sit above (installed and running on) of ESXi server, you will need other part of vSphere suit called vSphere client or vCenter. Now, vSphere client allows administrators to connect to ESXi servers and access or manage virtual machines. vSphere client is installed on the client machine (e.g. Administrator’s laptop). The vSphere client is used from client machine to connect to ESXi server and do management tasks.

So we have vSphere Client for manging the virtual servers. The what is vCenter? Why we need it?

vCenter Server: vCenter server is similar to vSphere client but it’s a server with more power. vCenter server is installed on Windows Server or Linux Server. VMware vCenter server is a centralized management application that lets you manage virtual machines and ESXi hosts centrally. vSphere client is used to access vCenter Server and ultimately manage ESXi servers. vCenter server is compulsory for enterprises to have enterprise features like vMotion, VMware High Availability, VMware Update Manager and VMware Distributed Resource Scheduler (DRS).

(For the time being don't go in details of above terms, we are just trying to understand the VMware jargon)

For example, you can easily clone existing virtual machine in vCenter server. So vCenter is another important part of vSphere package. You have to buy vCenter license separately.




The diagram above shows vSphere suite in a more descriptive way.

vSphere is a product suite (a group of software, you can say).

ESXi is a hypervisor installed on a physical machine. (A hypervisor or virtual machine monitor (VMM) is a piece of computer software, firmware or hardware that creates and runs virtual machines. A computer on which a hypervisor is running one or more virtual machines is defined as a host machine. Each virtual machine is called a guest machine.)

vSphere Client is installed on laptop or desktop PC and is used to access ESXi Server to install and manage virtual machines on ESXi server.

vCenter server is installed as virtual machine on top of ESXi server. vCenter server is a vSphere component which is mostly used in large environment where there are many ESXi server and dozens of virtual machines. The vCenter server is also accessed by vSphere client for management purpose. So, vSphere client is used to access ESXi server directly in small environment. In larger environment, vSphere client is used again to access vCenter server which ultimately manages ESXi server