“This is the sixth day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
Question 1
char *p[] = {“Shanghai”, “Beijing”, “Hongkong”}; The expression resulting in a j character is ()
A. *p[1] + 3
B. *(p[1] + 3)
C. *(p[3] + 1)
D. p[3][1]
analysis:
This problem is the investigation of pointer array, for the above definition we can draw the following diagram
You have to understand this graph for this code, otherwise you have problems understanding this code, and you also need to understand the precedence between the operators
So that’s choice B
Second question
The value of I is () after executing the following function
int f(int x)
{
return ((x > 2)? x * f(x -1) : 3);
}
int i;
i = f(f(2));
Copy the code
A. 30
B. Infinite recursion
C. 9
D. 2160
analysis:
So choice C
The third question
in int [p] [4] = {{1}, {3, 2}, {4, 5, 6}, {0}}; Where, the value of p[1][2] is
A. 1
B. 0
C. 6
D. 2
analysis:
This problem is a two-dimensional array examination
Incomplete initializations of two-dimensional arrays actively assign 0
So that’s choice B
Number 4
if z = 2 * (N + Y(5 + 1)), z = ()
#define N 3+1
#define Y(n) ((N+1)*n)
Copy the code
A. 60
B. 190
C. 248
[D]. All of the above is wrong
analysis:
define Replacement rule
The following steps are involved when the program extends #define to define symbols and macros
1️ one when calling macros, the parameter is first checked to see if it contains any symbol defined by #define. If so, they are replaced preferentially
2️ replacement text is then inserted into the program where the original text was. For macros, parameter names are replaced by their values
3️ finally, the result file is scanned again to see if it contains any symbols defined by #define. If so, repeat the process
note:
Other #define constants can appear in macro parameters and #define definitions. But for macros, recursion cannot occur, because macros do simple text substitution only once
When the preprocessor searches for symbols defined by #define, the contents of the string constant are not searched
code steps are as follows:
So that’s choice A
5
char a; int b; float c; double d; Then the expression a * b + d-c is of type ().
A. float
B. int
C. char
D. double
analysis:
arithmetic conversion
If the operands of an operator are of different types, the operation cannot proceed unless one of the operands is converted to the type of the other operand.
The following hierarchy is called ordinary arithmetic transformation
Long double double float unsigned long int long int unsigned int int
If the type of an operand is lower in the list above, the operand is first converted to the type of another operand and then the operation is performed. Low -> high bytes (if the operand is the same, the operation is converted to a higher precision)
So that’s choice D
Number 6
programming questions < difficulty coefficient
>
above:
The Fibonacci sequence is defined like this: [0] = 0 F F [1] = 1 for each I or 2: F = F [I] [I – 1) + F [I – 2] as a result, the Fibonacci sequence was shaped like an: 0, 1, 1, 2, 3, 5, 8, 13,… The numbers in the Fibonacci sequence are called Fibonacci numbers. You’re given an N, and you want it to be a Fibonacci number, and in each step you can change the current number X to either X minus 1 or X plus 1, and now you’re given a number N to figure out how many steps it takes to get a Fibonacci number.
Enter description.
The input is a positive integer N(1 ≤ N ≤ 1,000,000)
Output description:
Output a minimum number of steps to a Fibonacci number
example:
Input, 15
Input, 2
Platform: Visual Studio 2017 && Windows
Core Idea:
The original problem
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int main(a)
{
int n = 0;
scanf("%d", &n);
int f1 = 0;
int f2 = 1;
int f3 = 0;
while(1)
{
if(n == f2)
{
printf("%d\n".0);
break;
}
else if(n < f2)
{
if(abs(f1-n) < abs(f2-n))
{
printf("%d\n".abs(f1-n));
break;
}
else
{
printf("%d\n".abs(f2-n));
break; }}// Indicates that n is not in the interval between f1 and F2, and the Fib number needs to be iterated
f3 = f1 + f2;
f1 = f2;
f2 = f3;
}
return 0;
}
Copy the code
Question 7
programming problem < difficulty factor
>
above:
Implement a function that replaces each space in a string with “%20”. For example, if the string is “We Are Happy.”, the replacement string is “We%20Are%20Happy”.
Platform: Visual Studio 2017 && Windows
Core Idea:
wulitou
I’m sure some people will think this is a strange question, but it’s not a strange question.
When we go to Baidu to search the keyword “Wulitou”
Found that the link above replaced the space with “%20” why is the space replaced with %20
Pea looked it up on the Internet, and most of them said something like this:
The W3C standard states that Spaces in URL query parameters are written as plus signs; In RFC 2396, reserved characters in urIs should be escaped to %HH format
The ASCII value of a space is 32, and the hexadecimal value is 20
The dalai! I won’t go too far here
The original problem
#include<stdio.h>
#include<string.h>
void ReplaceSpace(char* str, int length)
{
//1. Count Spaces
int i = 0;
int spcount = 0;
for (i = 0; i < length; i++)
{
if (str[i] == ' ')
spcount++;
}
//2. Calculate the new length and the final position after replacing the space
int newlengh = length + spcount * 2;
int pos = newlengh - 1;
//3. Fill from back to front
for (i = length - 1; i >= 0; i--)
{
/ / space
if (str[i] == ' ')
{
str[pos--] = '0';
str[pos--] = '2';
str[pos--] = The '%';
}
/ / the Spaces
else{ str[pos--] = str[i]; }}}int main(a)
{
char arr[20] = "We Are Happy.";
ReplaceSpace(arr, strlen(arr));
printf("%s\n", arr);
return 0;
}
Copy the code