Saturday, May 22, 2010

Strings in c program?

what is the full defination of strings in c programing

Strings in c program?
A string in C is actually a character array. There are several methods of declaring the variable.


This first example declares a variable that can hold 4 characters. Below it is the initialized version


of the same declaration. The 5th space is for the end of string character that is automatically


added to the end of all strings:


char var[5];


char var[5] = "abcd";


char var[] = "abcd"; /* Equivalent to above. */


This type of declaration precludes the subsequent use of the assignment operator to


change the value stored in var. However, the value may be changed by using functions


such as strcpy(), fscanf(), and fgets().


Another declaration method is to declare a pointer variable. Notice in the first example a


size has not be determined. The assignment operator may be used to initialize the array


later but functions may not be used for initialization. Once initialized, the maximum size


of the array has been set as far as functions are concerned and functions may be used to


change the value. I think the assignment operator may be used to subsequently assign


longer strings to the pointer but I am not sure yet. The second example shows


initialization during declaration. p345


char *var;


char *var = "abcd";
Reply:An array of 8-bit characters, typically with a zero null terminator.





char myArray[] = "abcd";


is 5 characters ... the fifth is the null terminator.

email cards

No comments:

Post a Comment