Arrays And Pointers
A character variable allocates a single space for a character .So it requires array for accepting character data just like name, address, designation, etc…
Arrays are the continuous memory allocations for the same type of variables. The size of an array should be declared with its name.
The syntax to declare a character array;
data type space name of array[size of array]
char name[10];
int marks[10];
float weights[10];
Each memory space in an array is called element. For exception to others, the character array has a '/0' (back slash /zero) in the last element. So it is required to give an extra element for the back '/0'.
Values can be assigned to the variables, at the time of declaration .In the case of character variable or array the syntax is;
data type variable name =' ';
data type variable name[size] =" ";
char answer='y';
char name="apple";
Pointers are also a type of variable, but they store the addresses of other variables.
Pointer declaration
char name[10];
char* ptr=&name;
No comments:
Post a Comment