initilizing two dimensional char array
Posted Date Unknown sreeraj k r sreeraj k r 2 Comments

how to initialize character array in c++

See All Responses Below...
Author
Message Rating
Posted on: 30/07/2012
As you must know to initialize a char array in C++ is
- char chABCD[5] = "abcd"; // compiler appends a '' termination
- char chABCD[4] = { 'a', 'b', 'c', 'd' };

so, a 2 dimensional array is: 

char Board[3][3] = {{'x', 'x', 'o'}, {'x', 'o', 'x'}, {'x', 'x', 'o'}};



Posted on: 25/02/2016
The array of char elements called myword can be initialized with a null-terminated sequence of characters by either one of these two statements:

1
2
char myword[] = { 'H', 'e', 'l', 'l', 'o', '' };
char myword[] = "Hello"; 

In both cases, the array of characters myword is declared with a size of 6 elements of type char: the 5 characters that compose the word "Hello", plus a final null character (''), which specifies the end of the sequence and that, in the second case, when using double quotes (") it is appended automatically.
Share this page across other social networking sites



Please Login to Post Your Comments
Name (Max. 100 characters)
Please post your comments here
Select Language
Comments
   Design  HTML
Attach File(Max. Size: 2 MB)
A few simple rules when posting your Comments,
  1. Please post only answers relevant to the topic of discussion.
  2. Please dont misuse this site or do not be abusive, offensive, inappropriate,harass anyone on the boards or post ads or spam. Doing so will delete your inappropriate messages and will block or delete your account on this site. 

TekTipsDownload
GateExam
Academic Projects
TekTipsExperts



 
Site optimized for IE7, 1280 X 768 and above. Copyright © 2010 - 2018 KTS InfoTech
Site Developed Using KTS WebCloud