String: –

String: – It is a set of characters enclosed within pair of double quotes.

Ex: – “Hello”, “A”, “786”, “8”, “Hello World” etc.

In order to use string value, we can have two type of variables.

Array of character: – Declaration for array of character.

Syntax: –

                Char Array_Variable_Name[Size];

Ex: –

                char name[20];

Note: – Compiler automatically insert ‘\0’ (NULL) character at the end of string to indicate that string is being ended here.

Initialization of array of character: –

                Char ch[10]={‘S’,’t’,’u’,’d’,’e’,’n’,’t’,’s’};
                                Or
                Char ch[10]=“Students”;

Initialization of anonymous array: –

                Char str[]=”Hello”;

String pointer: – We have another way to read and display using string pointer.

Syntax: –

                Char *Pointer_Variable_Name;

Ex: –

                char *str;
                char *name;
                char *ch;

From the above example string pointer (str, name, ch).

Note: – String pointer holds 2 bytes in memory on 16 bit compiler and 4 bytes in memory on 32 bit compiler.

Initialization of string pointer: –

                *Pointer_Variable_Name=”Value”;

Ex: –

                char *str=”hello”;
                char *name=”vikrant kumar”;

From the above example number one the string constant hello will be stored separately some ware and its first address will be assign into string pointer str.

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: