The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 09-18-2008 08:15 PM
far pointer useless79 High Level Programming 1 11-08-2007 05:13 AM
address of pointer Poison Ivy High Level Programming 19 08-16-2006 07:04 AM
file pointer bankpro High Level Programming 1 02-20-2006 10:50 AM
pointer sarwan High Level Programming 1 11-15-2005 06:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-15-2006
sweta sweta is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 9
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
  #2 (permalink)  
Old 05-15-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,928
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;
  #3 (permalink)  
Old 06-04-2006
rengasamy rengasamy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 1
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0