C Programming - Pointers - Discussion
Discussion Forum : Pointers - General Questions (Q.No. 8)
8.
The operator used to get value at address stored in a pointer variable is
Discussion:
33 comments Page 1 of 4.
Parag said:
1 decade ago
Hello,
I have executing this code and thus it is perfect.
#include <stdio.h>
void main() {
// your code goes here
int x=10;
int *y;
y=&x;
printf("value at Y is %d\n",y);
printf("value at *Y is %d\n",*y);
printf("value at &Y is %d\n",&y);
}
Value at Y is -1076357592.
Value at *Y is 10.
Value at &Y is -1076357588.
--------------------------------------------------------------
So to conclude:
y gives address of x.
*y gives data of x.
&y gives the address of y. The memory which contains the address of x.
I have executing this code and thus it is perfect.
#include <stdio.h>
void main() {
// your code goes here
int x=10;
int *y;
y=&x;
printf("value at Y is %d\n",y);
printf("value at *Y is %d\n",*y);
printf("value at &Y is %d\n",&y);
}
Value at Y is -1076357592.
Value at *Y is 10.
Value at &Y is -1076357588.
--------------------------------------------------------------
So to conclude:
y gives address of x.
*y gives data of x.
&y gives the address of y. The memory which contains the address of x.
(1)
Govardhana kj said:
1 decade ago
For example;
consider int x=10;
int *y;
y=&x;
printf("value at Y is %d\n",y);
output is 10
bescause 10 is stored at address say 100(which named as 'x') and again we are declaring 'y' as pointer variable which holds address of another variable(here y holds adress of 'x')which is dereferenced using "&" opearator.
consider int x=10;
int *y;
y=&x;
printf("value at Y is %d\n",y);
output is 10
bescause 10 is stored at address say 100(which named as 'x') and again we are declaring 'y' as pointer variable which holds address of another variable(here y holds adress of 'x')which is dereferenced using "&" opearator.
Ravi ku said:
1 decade ago
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10;
int *p;
p=&a;
printf("value of A %d",a); //Output-10.
printf("value of A %d",*P); //Output-10.
printf("Address of A %p",a); //Output-fff2.
printf("value of p %d",p); //Output-fff2.
printf("Address of p %d",p); //Output-fff4.
#include<conio.h>
void main()
{
int a=10;
int *p;
p=&a;
printf("value of A %d",a); //Output-10.
printf("value of A %d",*P); //Output-10.
printf("Address of A %p",a); //Output-fff2.
printf("value of p %d",p); //Output-fff2.
printf("Address of p %d",p); //Output-fff4.
(2)
Lavanya said:
1 decade ago
int a=20,b=30,*p,*q;
p=&a;
q=&b;
p=q;
printf("%d%d",*p,*q);
Output is 30, 30
p=&a;
q=&b;
p=q;
printf("%d%d",*p,*q);
Output is 30, 30
Vinod said:
1 decade ago
Guys ramprasad is absolutely right. better u can understand by following example..
int x=10; //adress of x=100;
int *y; //address of y=102;
y=&x;
printf("%d",*y);//prints data of x is 10;
printf("%d",&y);//prints address of y is 102;
printf("%d",y); //prints address of x is 101;
int x=10; //adress of x=100;
int *y; //address of y=102;
y=&x;
printf("%d",*y);//prints data of x is 10;
printf("%d",&y);//prints address of y is 102;
printf("%d",y); //prints address of x is 101;
Swapnali said:
1 decade ago
Pointer is used to store the address of the variable of same type. Ex. char *ptr can be used to store address of char ch..
We use & operator to assign the address of variable to pointer Ex. ptr=&ch;
And we use * operator to get value stored at particular address stored in pointer var. Ex. char chh=*ptr;
We use & operator to assign the address of variable to pointer Ex. ptr=&ch;
And we use * operator to get value stored at particular address stored in pointer var. Ex. char chh=*ptr;
(1)
Maggie said:
1 decade ago
int *p; // creates a pointer to integer
int a=10//variable a has value as 10 and address as 2000
p=&a//here address of a(2000) is stored in p ie p is pointing to a
int b;//a variable
b=*p;//the pointer penetrates into a to fetch the value and stores it in b;
printf("%d",b);
output:10
int a=10//variable a has value as 10 and address as 2000
p=&a//here address of a(2000) is stored in p ie p is pointing to a
int b;//a variable
b=*p;//the pointer penetrates into a to fetch the value and stores it in b;
printf("%d",b);
output:10
Rathika.b said:
1 decade ago
No error program:
float y=3,*i;
i=&y;
printf("value of y is %f",y);
printf("value of i is %f",i);
printf("value of y is %f",*i);
But we know address are only integers.
Then how it is assign floating point?
float y=3,*i;
i=&y;
printf("value of y is %f",y);
printf("value of i is %f",i);
printf("value of y is %f",*i);
But we know address are only integers.
Then how it is assign floating point?
Sanu said:
1 decade ago
For example;
consider int x=10;
int *y;
y=&x;
printf("value at Y is %d\n",y);
output is 10
it is wrong if you r printing *y only get value 10
otherwise it returns address
consider int x=10;
int *y;
y=&x;
printf("value at Y is %d\n",y);
output is 10
it is wrong if you r printing *y only get value 10
otherwise it returns address
Rajasekar OMPARR said:
8 years ago
* is known as a de-referencing operator which de-reference the address stored in the pointer. That is fetched the value from that address which pointer is pointing to.
(3)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers