Based on information from http://technohitech.blogspot.com/, on c language, string is array of char variable. It means, if char consist of more than one digits then that array will be rated as string variable. So for define string variable still use char variable, but to show value of a char variable used code %c, as while to show value of a string variable used code %s which initial of string word.
On this section will be explained how to define string value/string content on program syntax using methode 1, please check it out!
Syntax of string variable on C programming language:
char *name_of_char = " ";
Use asterisk mark before name of char variable. Fill string is a character or array of character between double quotes mark
Example of using of string variable in which its value is defined on program syntax (Methode 1):
If there is something not understood please contact us... thank you : )
On this section will be explained how to define string value/string content on program syntax using methode 1, please check it out!
Syntax of string variable on C programming language:
char *name_of_char = " ";
Use asterisk mark before name of char variable. Fill string is a character or array of character between double quotes mark
Example of using of string variable in which its value is defined on program syntax (Methode 1):
- Open Dev C++
- File menu > New > Source File, then will be created a new worksheet titled Untitled1
- File menu > Save As. On Save as type: choose C source files (*.c) and on File name, example we give name define string methode 1.c
- First, type minimal required syntax on C programming:
main()
{
} - Add getch() function in main() function to show program result while be Run:
main()
{
getch();
} -
Define name of a variable as a string variable in which before the string variable name is given asterisk mark, and then define string value directly:
main()
{
char *name_of_string = "Thariq bin Ziyad";
getch();
} - Please Compile&Run and program has been OK
-
If we want to show string content, then can be used printf() function with using code %s::
main()
{
char *name_of_string = "Thariq bin Ziyad";
printf("%s", name_of_string);
getch();
} - For more interesting can be added sentence:
main()
{
char *name_of_string = "Thariq bin Ziyad";
printf("String is defined on program syntax is: %s", name_of_string);
getch();
} -
We can also add others string variable which its value is defined directly on program syntax:
main()
{
char *name_of_string = "Thariq bin Ziyad";
char *name_of_string2 = "Learning C Programming Language";
printf("First String content is defined on program syntax is: %s\n\n", name_of_string);
printf("Second String content is defined on program syntax is: %s", name_of_string2);
getch();
}
If there is something not understood please contact us... thank you : )
0 komentar:
Posting Komentar