Difference between revisions of "Interview Preparation topic : Pointers in C"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Created page with "<b>What is a Pointer?</b> A pointer is a variable which contains the address in memory of another variable. Every variable is a memory location and every memory location has...")
 
Line 2: Line 2:
  
 
A pointer is a variable which contains the address in memory of another variable. Every variable is a memory location and every memory location has its address defined which can be accessed using ampersand (&) operator, which denotes an address in memory.
 
A pointer is a variable which contains the address in memory of another variable. Every variable is a memory location and every memory location has its address defined which can be accessed using ampersand (&) operator, which denotes an address in memory.
 +
 +
Lets Look at the following example:
 +
 +
 +
#include <stdio.h>
 +
int main ()
 +
{
 +
  int  temp;
 +
  int temp1;
 +
  printf("Address of temp variable: %x\n", &temp );
 +
  printf("Address of temp1 variable: %x\n", &temp1 );
 +
  return 0;
 +
}
 +
 +
When the following code is compiled and executed:
 +
 +
Address of temp variable: edf53400<br>
 +
Address of temp1 variable: adf9a5f6

Revision as of 22:20, 10 December 2016

What is a Pointer?

A pointer is a variable which contains the address in memory of another variable. Every variable is a memory location and every memory location has its address defined which can be accessed using ampersand (&) operator, which denotes an address in memory.

Lets Look at the following example:


  1. include <stdio.h>

int main ()

{
  int  temp;
  int temp1;
  printf("Address of temp variable: %x\n", &temp );
  printf("Address of temp1 variable: %x\n", &temp1 );
  return 0;

}

When the following code is compiled and executed:

Address of temp variable: edf53400
Address of temp1 variable: adf9a5f6