top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can we refer pointer and its working with the help of & operator?

+8 votes
538 views
How can we refer pointer and its working with the help of & operator?
posted Dec 17, 2013 by Prachi Agarwal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
int  var = 20;   /* actual variable declaration */
int  *ip;        /* pointer variable declaration */
ip = &var;  /* store address of var in pointer variable*/
printf("Address of var variable: %x\n", &var  );
/* address stored in pointer variable */
printf("Address stored in ip variable: %x\n", ip );
/* access the value using the pointer */
printf("Value of *ip variable: %d\n", *ip );

" &var " gives the value where 20 is stored and pointer ip is pointing.
And " *ip " will return the value stored in the address it is pointing.

answer Dec 17, 2013 by Satyabrata Mahapatra
You are right Satyabrata.
One More thing : Accessing address of a register is invalid.

register int i = 10;
 int *a = &i;

This  is wrong.
Similar Questions
+4 votes

What will be the output of this code?

 void main(){
       int i=320;
       char *ptr=(char *)&i;
       printf("%d",*ptr); 
    }
+5 votes
#include<stdio.h>
#include<string.h>
main()
{
    char p[100];
    int i,len;
    printf("Enter a string\n");
    scanf("%[^\n]",p);
    len=strlen(p);
    for(i=0;i<len-1;i++)
    {
        if(a[i]==a[i+1])
              p[i]=p[i+1];
    }
    printf("String :  %s\n",p);
}
...