Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regarding variable declaration, i know about interger types
#1
Dear Sir,

Regarding variable declaration, i know about interger types and charecter types but what is data type of string? let say, in the assignment, we have one input that "take the customer name" so that is not character. what should we do in that case? Please explain in detail with examples.



Thank you very much.
Reply
#2
Dear student!
In such case where we need to store string, we use char array data type. Which is used to represent a sequence of characters regarded as a single data item. In C++, strings of characters are held as an array of characters, one character held in each array element. In addition a special null character, represented by `\0', is appended to the end of the string to indicate the end of the string. Hence if a string has n characters then it requires an n+1 element array (at least) to store it. Thus the character `a' is stored in a single byte, whereas the single-character string "a" is stored in two consecutive bytes holding the character `a' and the null character.

For example: A string variable s1 could be declared as follows:
char s1[10];
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  forward declaration instead of header files in c++ 2011 Vuhelper 0 1,873 06-15-2011, 06:22 PM
Last Post: Vuhelper
  Variable Access Speed in C++ Vuhelper 0 1,030 06-12-2011, 07:23 PM
Last Post: Vuhelper
  Declaration are Definition are the function in c++ May 2011 Vuhelper 0 3,850 05-30-2011, 03:20 PM
Last Post: Vuhelper
  static variable is called the global veriable ? saneha 1 1,889 05-02-2011, 06:51 AM
Last Post: Vuhelper
  Static Variable in c++ 2011 saneha 1 2,417 04-29-2011, 08:32 AM
Last Post: Vuhelper
  what are instance variable in c++ ? saneha 1 6,515 04-29-2011, 08:30 AM
Last Post: Vuhelper
  Q: What is the difference between function declaration and function define with exp sana.pari 1 31,478 04-24-2011, 06:28 PM
Last Post: Support
  character variables and assignment contain characters variable requirement sana.pari 1 3,395 04-24-2011, 06:20 PM
Last Post: Support
  How many types of Array are there in C++? sana.pari 1 2,022 04-24-2011, 05:14 PM
Last Post: Support

Forum Jump:


Users browsing this thread: 1 Guest(s)