Detailed explanation of the use of character arrays and strings in C language
1. Definition and initialization of character array
The easiest way to understand the initialization of character array is to assign characters to each element in the array one by one.
char str[10]={ 'I',' ','a','m',' ','h','a','p','p','y'};
That's it The 10 characters are assigned to the 10 elements from str[0] to str[9] respectively. If the number of characters provided in the curly braces is greater than the array length, it will be treated as a syntax error; if it is less than the array length, only these characters will be included in the array. For the first elements, the remaining elements are automatically set to empty characters (i.e. '
3. String representation
In C language, you can use two methods to represent and store strings:
(1) Use a character array to store a string
char str[ ]="I love China";
( 2) Use a character pointer to point to a string
char* str="I love China";
For the second representation method, some people think that str is a string variable, and they think that the string constant "I love China" should be directly defined when defining it. Assigning to the string variable is incorrect.
C language handles string constants as character arrays. A character array is opened in the memory to store string constants. When the program defines the string pointer variable str, it only changes the first address of the string (that is, the address where the string is stored). The first address of the character array) is assigned to str.
String output in both representation methods uses
printf("%sn",str);
%s means outputting a string, giving the character pointer variable name str (for the first representation method, the character array name is is the first address of the character array, which is consistent with the meaning of the pointer in the second type), the system first outputs the character data it points to, and then automatically adds 1 to str to point to the next character..., This continues until the end-of-string identifier "

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.