Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 5th, 2008, 3:41 PM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
char[] vs char*

I am confused as to the difference between a char array and a char pointer in C. For example:

char a[] = "one";
char *b = "two"

As I understand it, both are essentially pointers to the first character of an array except a can be modified and b cannot. Why is this?

If I then write char *c = a;, can c be used to modify the character array a?

Compare the following two functions declarations:

void f1(char x[]);
void f2(char *x);

If I pass a char[] to f2, can I modify it, or only if I pass it to f1? I assume it would be incorrect to pass a char* to f1--is this true?

Finally, compare the following two declarations for main:

int main(int argc, char *argv[]);
int main(int argc, char **argv);

Does the latter indicate that the contents of argv can be modified? Or are the two declarations identical?

Thanks for any help clearing this up.
titaniumdecoy is online now   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
25 ways to efficiently sort an array/list of integers Jimbo Software Design and Algorithms 36 Mar 3rd, 2008 6:31 AM
500 Ways to Program Numbers 1 Through 10! Sane Coder's Corner Lounge 637 Jan 5th, 2008 10:15 PM
char * to char[] titaniumdecoy C++ 6 Jul 28th, 2006 12:53 PM
char[] problem Kilo C++ 13 Jun 19th, 2006 2:18 AM
Convert char[] to int King C++ 18 Jan 31st, 2006 3:55 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:08 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC