example programs
What is meant by pointer in c programming?
Pointer:
*********
Poiinter is a variable which contains the address of another variable's memory location. Pointer provides an indirect way of accessing the value stored in a variable
%26amp; - used to return the address of a variable
* - used to store a value at a particular address.
Example:
**********
main()
{
int i=3;
int *j;
j=%26amp;i; /*returns address of i %26amp; stored in integer pointer variable j
printf("\naddress of i=%u"%26amp;i);
printf("\naddress of i=%u",j);
printf("\naddress of j=%u",%26amp;i);
printf("\nvalue of j=%d",j);
printf("\nvalue of i=%d",i);
printf("\nvalue of i=%d",*(%26amp;i));
printf("\nvalue of i=%d,*j);
getch();
}
output
*******
address of i=6485
address of i=6485
address of j=3276
value of j=6485
value of j=3
value of i=3
value of i=3
**************************************...
hope this helps....
Reply:No end for doubts and todays programming challenges are much more complicated. Pointers are trivial stuff and don't bother about it.
Reply:A pointer is not a normal variable, it is a special type of variable which is used to store the address of a normal variable.It is used to increase the speed of the system.we can perform add,sub on pointer variables.
Reply:Pointer is a variable which points to some other variable...
Reply:Pointer is a special vatiable that holds the adress of another variable.
Its most used applications can be found in fuctions,dynamic memory allocation and files.
main()
{
int *p;
int a[5],i;
printf("Enter array");
for(i=0;i%26lt;5;i++)
{
scanf('%d",%26amp;a[1]);
}
p=a;
printf("Display elements using pointers \n");
for(i=0;i%26lt;5;i++)
{
printf("%d",a+i);
}/*hope this helps*/
}
Reply:http://vergil.chemistry.gatech.edu/resou...
http://www.imada.sdu.dk/~svalle/courses/...
http://www.lysator.liu.se/c/bwk-tutor.ht...
http://www.cs.cf.ac.uk/Dave/C/
Reply:try this
http://vergil.chemistry.gatech.edu/resou...
Reply:A pointer can be used to access a data object indirectly through memory address.
· The content stored in a pointer variable is the address of another variable.
· The pointer is said to point to a variable if it contains the address of the variable.
· Pointers are stored in 4 bytes of memory. (2 bytes for older machines)
Pointers are declared using an asterisk * , as follows:
eg: Pointer declaration for INTEGER : int *px;
eg: Pointer declaration for FLOAT : float *px;
( Special: A pointer variable declared with type void can point to any type of data object)
void *px;
Simple example, you will understand by studying the addresses:
void main(void)
{
int x, y;
int *px; //pointer variable
printf("The address of the variable x (%26amp;x) is %lu\n", %26amp;x);
px = %26amp;x; //assign the address of x to px, i.e. px points to x
printf("The value(address) stored in the pointer variable px is %lu\n\n",
px); //Same as %26amp;x
printf("The address of the variable y (%26amp;y) is %lu\n", %26amp;y);
px = %26amp;y; //assign the address of y to px, i.e. px points to y
printf("The value(address) stored in the pointer variable px is %lu\n",
px); //Same as %26amp;y
} //main
Reply:it keeps the address of a variable.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment