![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to replace any char with newline char. | mightysam | Shell Programming and Scripting | 5 | 2 Weeks Ago 05:15 PM |
| far pointer | useless79 | High Level Programming | 1 | 11-08-2007 01:13 AM |
| address of pointer | Poison Ivy | High Level Programming | 19 | 08-16-2006 04:04 AM |
| file pointer | bankpro | High Level Programming | 1 | 02-20-2006 06:50 AM |
| pointer | sarwan | High Level Programming | 1 | 11-15-2005 02:41 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Regarding char Pointer
Hi,
char *s="yamaha"; cout<<s<<endl; int *p; int i=10; p=&i; cout<<p<<endl; 1) For the 1st "cout" we will get "yamaha" as output. That is we are getting "content of the address" for cout<<s. 2) But for integer "cout<<p" we are getting the "address only". Please clarify how we are getting content of the address for char type only but not for other types. Thanks Sweta |
| Forum Sponsor | ||
|
|
|
|||
|
character pointer types are special, they can point to strings of the standard C kind -- characters 1-127 in the string, character 0 as the terminator. It assumes they are C strings and thus is able to know where they end.
Integer pointer types do NOT define strings of any type that C++ knows, they're just pointers to integers. It could be pointing to one integer or many. To print the content of a pointer really isn't that difficult. You can do: Code:
cout << (*p) << endl; cout << p[0] << endl; |
|
|||
|
Quote:
u will give a *p in cout code , then only u will get the value. int *p; int i=10; p=&i; cout<<*p<<endl; Regards.. Rengasamy.E |
|||
| Google The UNIX and Linux Forums |