![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Expert Programmer
|
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. |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |