The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-14-2006
Registered User
 

Join Date: Nov 2005
Posts: 9
Stumble this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-15-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
Stumble this Post!
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;
Reply With Quote
  #3 (permalink)  
Old 06-03-2006
Registered User
 

Join Date: Jun 2006
Posts: 1
Stumble this Post!
Quote:
Originally Posted by sweta
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
Hi,

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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0