当前位置:网站首页>Half search, character array definition, character array uses D11

Half search, character array definition, character array uses D11

2022-06-26 13:53:00 Apple ADC

One . Use half search to learn debugging

Find the premise in half : The data must be in order .

In the length of len Array of arr in , Find keywords key, Successfully returned subscript , Failure to return -1

Two . Character array definition

1. hold drr[10] The elements in are represented in turn

#include<stdio.h>
int main()
{
	int arr[]={1,2,3,4};
	char brr[10];
	short crr[10];
	double drr[10]={12.3,34.5,56.7,67.9};
	for(int i=0;i<sizeof(drr)/sizeof(drr[0]);i++)
	{
		printf("%f",drr[]);
	}
	return 0;
 } 

2.0 In the form of :0,0.0,false,NULL,'\0'

    character : single quote '' One character included , for example 'a','1','0'

    character string : Use double quotes "" A string included , from 0 One or more characters , for example " ","1234","adf  ab"

                  There must be a hidden '\0' End of expression           '\0' Is the end of the string

    Is it a string : Is there any " " perhaps Is there any '\0'

    Report errors : Ironing : Local variable uninitialized

int main()
{
	char arr[5]={'a','b','c','d','e'};// It's not a string 
	char brr[10]={'a','b','c','d','e'};// Uninitialized section displays '\0'    Is string 
	char crr[]={'a','b','c','d','e'};// It's not a string 
	char drr[10];// It's not a string 
	// Character array specific definitions 
	char err[]="abcd";
	char frr[4]="abcd";// Report errors , There's also a hidden one '\0'
	char grr[10]="abcd";
	char *hrr="abcd";// String constant contents cannot be modified  
}

3、 ... and . The character array uses

#include<stdio.h>
int main()
{
	char str1[10]="abcde";// The overall assignment of the whole group has only one initialization opportunity  
	char str2[10]="xyz";
	char str3[10];
	str2=str3; // Report errors , You cannot assign values as a whole 
	str1+=str2;// Report errors 
	int i;
	for(i=0;i!='\0';i++)// Using strings '\0' The closing mark   
	{ 
	   str2[i]=str1[i];
    }
    str2[i]='\0';// Add end tag '\0'
	printf("str1=%s\n str2=%s\n",str1,str2);
	return 0; 
 } 

原网站

版权声明
本文为[Apple ADC]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170512184740.html