Sunday, July 12, 2009

What is pionters in "c" language?

I cannot understand "c" language . my sir is telling in "c" pionters are very important. explain about pointers.

What is pionters in "c" language?
A "pointer" is a variable that holds a memory address. In C, they are declared like this:





int c; // integer variable


int *ptr_c; //pointer to integer variable





To initialise the pointer, you need to use the address operator (%26amp;) like this:





ptr_c = %26amp;c;





This assigns the memory address or lvalue to the pointer variable c_ptr. You use this to communicate between functions by using pointers to pass the value of the pointer to a function that you call. In the body of the program that pointer *ptr_c refers to the value (rvalue) that is stored at the address ptr_c.





Think of a pointer as being a mailbox address and the variable the pointer points to as the actual mail itself.





Note: Use of uninitialized pointers (dangling pointers) is a leading cause of bugs in C/C++.
Reply:as an example, pointer to int will be like 'int *ptr;'.





When the parser look at a statement like this, it will enter the '*' in its own place. next time, when ptr is used, the compiler will look up the ptr's field. there, a '*' will be seen. here the '*' will instruct the compiler that the ptr itself is not containing the value we are looking for, but the value stored in ptr is the address where the value we are loking for is stored.





baah! read your prescribed books, discuss at your study groups.
Reply:You have to learn basic concepts of C-Language and then you can go to learn advanced concepts of C-Language like pointers, structure etc.


In short pointers are those variables which holds the address of another variable.


eg:





int a=10; //this statement defines integer type variable "a";


int *p; //this statement defines a pointer varibale "p" which will point to(or hold the address of integer type variable)





p=%26amp;a; //this stores address of variable "a" to pointer "p";





printf("%d", *p); //prints value at address stored in "p" i.e 10;


print("%d",p);//prints address of "a" stored in "p";








for more information visit my blog


http://codesbyshariq.blogspot.com
Reply:http://home.netcom.com/~tjensen/ptr/poin...
Reply:Simply Pointer is the variable that stores the address of another variable.





int p,*pp;


p=4;


// now p contains value 4


pp=%26amp;p;


// and pp contains address of p
Reply:Pointers are memory locations which stores data and address of that memory location. You can check it out if you type


printf("%d",*ptr); it will show you the contents of the address and


printf("%ld",%26amp;ptr); it will show the address


if *ptr++ then the data gets added by one


if ptr++ then the adress gets incremented by one
Reply:U meant Pointers, well its an address for memory of the computer which can be directly used in C programming.
Reply:Well its simple you can get good definition of it at wikipedia.com .but ill give you a simple example for this .





guess you ,myself and another friend of yours are close friend group. your friend is gone to meet the doctor ,you come and ask me where is your friend ill reply to you saying that your friend has gone to meet the doctor .so you will come to know that your friend has gone to meet the by me .


so i become a pointer of your friend i point you to him ,thats it


that was a example of an pointer ...bye
Reply:Pointer is a data type that store the memory reference (memory address) of another value (variable) in the memory.





Refer wikipedia for full explanation


http://en.wikipedia.org/wiki/Pointer


No comments:

Post a Comment