I. Answer questions (write t for the correct question, write F for the wrong question, and explain the cause. 4 points for each question, a total of 20 points)
1. An array defines int A [2] [2] = {1}, {2, 3}; then the value of a [0] [1] is
0. T
2. If int (* PTR) [] is used, PTR is the name of a one-dimensional array. F
3. the pointer can be>, <, >=, <=, = in any case. F
4. In the switch (c) statement, C can be int, long, Char, float, and unsigned.
Int type. F
5. # define print (x) printf ("the no," # X ", is") T
2. Fill in blank questions (30 points in total)
1. In Windows, write the running result. Every blank value is 2 points, totaling 10 points.
Char STR [] =
"Hello ";
Char * P = STR;
Int n = 10;
Sizeof (STR) = ()
Sizeof (p) = ()
Sizeof (n) = ()
Void func (char STR [1, 100]) {}
Sizeof (STR) = ()
[Answer] 6; 4; 4; 4;
2. Void setmemory (char ** P, int num)
{
* P = (char *) malloc (Num );
}
Void test (void)
{
Char * STR = NULL;
Getmemory (& STR, 100 );
Strcpy (STR, "hello ");
Printf (STR );
} What are the results of running the test function?
[Answer] // hello
3. Set int arr [] = {6, 7, 8, 9, 10 };
Int * PTR = arr;
(PTR ++) + = 123;
Printf ("% d, % d", * PTR, * (++ PTR ));
[Answer]/* 8 */
2. programming questions (question 1: 20; Question 2: 30)
1. If no database function is used, the int strcmp (char * Source, char * DEST) function returns 0, not equal to-1;
/*
Int strcmp (char * Source, char * DEST ){
If (Source = NULL | DEST = NULL)
Return-1;
While (* Source ++ = * DEST ++)
If (* Source! = '\ 0' & * DEST! = '\ 0') return 0;
Return-1;
}
2. Write a function
Int fun (char * P) checks whether a string is a return object. If it is 1, it is not returned.
0, error returned-1
// Ex_exam.cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <iostream> using namespace STD; int fun (char * P) {If (P = NULL) Return-1; int n = strlen (P ); int I; for (I = 0; I <= n/2-1; I ++) {If (P [I]! = P [n-1-i]) return 0;} return 1;} int _ tmain (INT argc, _ tchar * argv []) {cout <fun (0) <Endl; return 0 ;}
(1) What is pre-compilation and when pre-compilation is required:
[Answer] 1. Always use large code bodies that are not frequently modified. 2. A program consists of multiple modules. All modules use a set of standard inclusion files and the same compilation options. In this case, all contained files can be precompiled into a precompiled header.
(2) char * constp; char const * P
; Const char * P What are the differences between the three above?
[Answer] char * const P; // constant pointer. The value of P cannot be changed to charconst * P. // the pointer to a constant cannot be changed to the constant value.
Const char * P; // and char const * P
(3) Char str1 [] = "ABC ";
Char str2 [] = "ABC ";
Const charstr3 [] = "ABC ";
Const charstr4 [] = "ABC ";
Const char * str5 = "ABC ";
Const char * str6 = "ABC ";
Char * str7 = "ABC ";
Char * str8 = "ABC ";
Cout <(str1 = str2) <Endl;
Cout <(str3 = str4) <Endl;
Cout <(str5 = str6) <Endl;
Cout <(str7 = str8) <Endl;
The result is: 0 0 1 1 str1, str2, str3, and str4 are array variables,They have their own memory space.Str5, str6, str7, and str8 are pointers pointing to the same constant area.
(4) Are there any problems with the usage of the two sizeof in the following code?
[C easy] void uppercase (char STR []) // set Str
The lowercase letters in are converted into uppercase letters {for (size_t I = 0; I (y )? (Y) :( X) // No ';' at the end ';'
10. Infinite loops are often used in embedded systems. How do you use C to write an infinite loop. Answer: While (1) {} or
For (;;)