LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2010, 12:56 PM   #1
jamesbon
Member
 
Registered: Jun 2010
Posts: 147

Rep: Reputation: 9
character arrays in C


I was reading Kernighan Ritchie book chapter 4 which deals with character pointers.
I am not able to understand following different type of declarations

Code:
char aname[][15] = { "Illegal month", "Jan", "Feb", "Mar" };
char amessage[] = "now is the time"; 
char *name[] = { "Illegal month", "Jan", "Feb", "Mar" };
What is the difference between these three?
 
Old 11-03-2010, 01:58 PM   #2
widapol
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Rep: Reputation: 0
First line, you will have an array of strings, length of each strings should be not larger than 15 characters, and the constants will be assigned to aname[0], aname[1],aname[2], aname[3] string respectively.
Second line, you will have a string.
Third line, you will have pointer of string, somewhat equivalent to an array of strings.
For more about difference between string array and pointer. Check this out.

Last edited by widapol; 11-03-2010 at 02:03 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting: parsing a text file character-by-character Completely Clueless Programming 13 08-12-2009 09:07 AM
To know the function on checking whether a character is ascii or unicode character. murugesan Programming 2 01-23-2009 01:07 PM
Arrays of Structures to Arrays of Classes knobby67 Programming 1 01-01-2008 01:39 PM
Question about outputing arrays with pointers, then just arrays... RHLinuxGUY Programming 1 04-12-2006 05:40 AM
character arrays; simple problem! drgilberto Programming 2 02-12-2006 04:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration