I see you have the answer in front of me. I just made the last two. I’ll send you the whole thing again!
1. Talk about the differences between the following statements
char *a = "abc";
char b[] = "abc";
p>
char c[3] = "abc";
a is a character pointer variable, the starting content is the first address of the string "abc", the string "abc" is stored in the constant district.
b[ ] occupies 4 bytes, b[0]='a', b[1]= 'b', b[2]=' c', [3]='\0 '
c[3] occupies 3 bytes, c[0]='a', c[1]= 'b', c[2]= 'c'
2. The following is a 32-bit C program under Windows NT. Please fill in the blanks.
For example: int i; long int j; char k; sizeof(i) = 4; sizeof(j) = 8; sizeof(k) = 1;
In 32 bits Under the system, the number of bytes occupied by shaping is 4. The number of bytes occupied by long integer is 8, and the number of bytes occupied by character type is 1.
(1)
typedef struct
{
int iPara1;
union
< p>{char iPara2[5];
int iPara3;
char iPara4;
} Params;
char cPara5;
char cPara6[12];
} TEST_INFO_T;
TEST_INFO_T stTestInfo;
Please calculate
p>sizeof (stTestInfo) = 28
(I have not verified this answer, but I feel that the size of the structure depends on the number of alignment digits. The normal alignment digits are 4, which may be different. The default settings of the system are different. I remember that the default setting of Solaris I used was 8, you can also change it yourself.
)
(2)
void Func ( char str[3])
Please calculate
sizeof( str ) =4 < /p>
(3)
void *p = malloc( strlen(“hello world”) );
Please calculate
sizeof ( p ) =4
(4)
char str[] = “Hello” ;
char *p = str ;
int n = 10;
Please calculate
sizeof (str) =6
sizeof ( p ) =4
sizeof ( n ) =4
3. What is the output result on the terminal after running this program?
char acFileName_p[2][50]; /*Global variable, valid during the entire program running*/
int FileExists(char* name)
{
int i;
for(i = 0; i < 2; i++)
{
if( strcmp (( char*) name, (char*)acFileName_p [i] ) = = 0)
{
return 1;
}
}
return 0;
}
void CheckFileName(char *name)
{
static char suffix[3] = "_1";
if( FileExists(name) )
{
if(suffix[1] != '1' )
{
name[strlen(name) - 2] = '\0';
}
strcat(name, suffix);
suffix[1]++;
CheckFileName(name);
}
else
< p> {suffix[1] = '1';
}
}
main
{
char cString1[50];
char cString2[50];
strcpy(acFileName_p[0], "test1");
strcpy(cString1, "test1");
strcpy(cString2, "test2");
CheckFileName(cString1);
printf(" Output1 = %s\n", cString1);
CheckFileName(cString2);
printf("Output1 = %s\n", cString2);
strcpy(acFileName_p[1], cString1);
CheckFileName(cString1);
printf("Output1 = %s\n", cString1);
}
Answer:
Output1 = test1_1
Output1 = test2
Output1 = test1_1_1
Yours There is an error in the code. The most obvious one is the main function. You have to add the right parentheses! ! !
4. Please find all the errors in the following code
Explanation: The following code reverses a string, such as "abcd" becomes "dcba" in reverse order
(1)#include"string.h"
(2)main()
(3){
(4) char* src="hello,world";
(5) char* dest=NULL;
(6) int len=strlen(src);
( 7) dest=(char*)malloc(len);
(8) char* d=dest;
(9) char* s=src[len]; p>
(10) while(len--!=0)
(11) d++=s--;
(12) printf("%s", dest);
(13) return 0;
(14)}
I re-wrote the changes,
#include
#include
#include
int main()
{
char *src = "hello,world";
char* dest =NULL;
int len ??= strlen(src);< /p>
dest = (char*)malloc(len);
char* d = dest;
char* s= &src[len-1]; p>
printf("%s\n",s);
printf("%d\n",len);
while(len--!= 0){
*(d++) = *(s--);
}
printf("%s\n",dest);< /p>
free(dest);
dest=NULL;
return 0;
}