CSDN read some C 艹 pen questions

Source: Internet
Author: User

Organized from: http://blog.csdn.net/djb100316878/article/details/39720055, it has a lot of errors ...

1:

On the 32-bit machine, according to the following code, what is the correct statement? ( )
Signed char a = 0XE0;
unsigned int b = A;
unsigned char c = A;
A. a>0 && c>0 for Real
B. A = = C is True
The hexadecimal representation of C. B is: 0xffffffe0
D. None of the above is right.

Explanation: 0xe0 decimal is 2,242 binary to 11100000

Char A is a signed type, the first bit is a sign bit, 0 represents a positive number, and 1 represents a negative number, so char a =-32;

and Char c is an unsigned type, so a and C are definitely not equal, so a, b error;

Look at c A for char type one byte, b is int type, account for 4 bytes, assign one byte to 4 bytes

The missing should complement the sign bit, A is 1110000 so B is 1111 1111 1111 1111 1111 1111 1110 0000 is 0xffffffe0; so choose c;


2:

Which of the following options can be compiled? ( )
int i;
Char a[10];
string f ();
String g (string & str);
A. if (!! i) {f ();}
B. G (f ());
C. a=a+1;

D. G ("abc");

Explain:

First exclude C, the array name can not be used in this way, a can not be used as an lvalue, because a is a constant pointer;

Look again D, "ABC" is a const char * type, type mismatch, so d wrong;

The most critical look at the B option, string F () returns the object of a temporary variable, and the parameter of string g (string& str) is a non-const reference, there is a syntax rule in C + +, non-const references cannot be initialized with temporary variables, C + + This is used in order to limit potential errors. As for the reasons, many of the online statements do not have a unified, but in C + + so clearly defined, I myself feel G (f ()); F () returns the temporary object, if passed to a non-const reference, may be modified, so unsafe, may cause a lot of errors.

Look at a is actually very simple, is right

3. int a[10]; Which of the following addresses do not represent a[1]? ( )
A. a+sizeof (int)
B. &a[0]+1
C. (int*) &a+1
D. (int*) ((char*) &a+sizeof (int.))

Explain:

Type* A;

A + N calculation rule

(unsigned int) A + n*sizeof (int)

So the address of &a[1] is: (unsigned int) A + 1* sizeof (int);

First look at a, bring into the formula: (unsigned int) A + 4*sizeof (int); error;

Again see b,&a[0] is the address of the first element, with the formula is (unsigned int) A + 1* sizeof (int);

look at C again, first here &a why add int*, because &a is the first address of an array, its type is int (*) [10], and A is an array The address of the first element, which is of type int (*); so c is correct.

Then see D first convert &a to char* type so this is equivalent to: (unsigned int) a + sizeof (int) *sizeof (char);

5:

Which of the following function calls must go into the kernel to complete? ( )
A. fopen
B. Exit
C. memcpy
D. strlen

Explain:

Select Ab,fopen Open a file, to invoke the thread kernel, the exit operating system has this permission to exit, so also call the kernel

CD is just a simple string processing, do not need to enter the kernel;

6:

What are the necessary conditions for a deadlock? ( )
A. Mutex conditions
B. Request and hold
C. Non-deprivation
D. Cyclic waiting

Explain:

Choosing ABCD does not explain

7:

There are two threads, initially n=0, one thread executing n++; n++; Another executive n+=2; Q, what is the last possible n value? ( )
A. 1
B. 2
C. 3
D. 4

Explanation: n++ and n+=2 in the assembly there are three processes first: the value of reading N; the second: the value of n plus 1 or plus 2; Third: write the value of N to memory

These three processes may be interrupted, and the result is that BCD is possible.


8. Which of the following statements is correct? ( )
A. Arrays and linked lists can be accessed randomly
B. Insertion and deletion of arrays can reach O (1)
C. Hash table cannot be checked by scope
D. Two fork tree cannot be accessed linearly


Explain:

A array can be accessed randomly, and the list cannot

b array insertion to move a lot, not O (1);

D two fork tree can be linearized first, then linear access, (I do not understand, data structure is not good) "estimate is the first to traverse the group, then become a linear access?" 】

C correct

9. What is the lower limit of time complexity for comparison-based sorting? ( )
A. O (N)
B. O (n^2)
C. O (NLOGN)
D. O (Logn)

Explanation: Choose c to memorize

10. For the following procedure, on a big endian 32-bit computer, what is the result of B? ( )
unsigned int a = 0x1234;
Char B = * ((char*) &a);
A. 0x12
B. 0x34
C. 0x00
D. Program crashes

Explain:

Big-endian mode: The high position exists at the low address. The small-end mode is a high-level presence in the higher address.

Unsigne int a = 0x1234

0x00 0x00 0x12 0x34

Low----------------------High

b Take the first address of the lower address, so it is 0x00;

11. Write a function to find a larger value between two integers a and b. The request cannot be used if, while, switch, for,?: and any comparison statements.

int max (int a, int b)  {      int d = A-C;      int flag = (unsigned int) d >> 31; The symbol is shifted to the lowest bit, so that flag is 0 or 1, so it can't fill the sign bit! So for unsigned int       int array[] = {A, b};      return array[flag];  }  

1. Consider the function prototype void Hello (int a, int b=7, char* pszc= "*"), the following function call belongs to the illegal call is ()
A. Hello (5)
B. Hello (5, 8)
C. Hello (6, "#")
D. Hello (0, 0, "#")

Explanation: The default variable selected for the parameter in C + + C

2. A complete binary tree with 800 nodes, and ask how many leaf nodes are there? ( )
A. 100
B. 200
C. 400
D. Cannot be determined

Explanation: The depth of the complete binary tree is first obtained h = log2 (800) + 1 = 9 + 1 = 10;

Then the number of nodes in the front 9 layer is 2 9 power-1 is 511;

The last layer of nodes is 800-511 = 289;

289 = 288 + 1; 288 so there are 144 nodes in the nineth layer;

The 9th row of the complete binary tree also has leaf nodes;

So the nineth layer has 144+1 = 145 nodes is not a leaf node;

256-144-1 = 111 leaf nodes;

So there are 111+289 = 400 leaf nodes;


Full binary Tree features:

leaf knot Point It is only possible to appear on the largest two levels, and for any node, if the maximum level of the descendants under the right branch is L, then the maximum level of the descendants under the left branch of the tree must be L or l+1;

If a two-fork tree with a depth of n nodes is K, each of its nodes corresponds to a node one by one with a depth of k in the full two-fork tree numbered 1~n, which is called a complete binary tree.can be deduced according to the formula, assuming that N0 is the total number of nodes with a degree of 0 (i.e.Leaf knot Pointnumber), N1 is the total number of nodes with a degree of 1, N2 is the total number of nodes with a degree of 2, which is known by the nature of the two-fork tree: n0=n2+1, then n= n0+n1+n2 (where n is the total number of nodes of a fully binary tree), the N2 is eliminated by the above formula: N= 2n0+n1-1, because the total binary tree in the 1 node is only two possible 0 or 1, resulting in n0= (n+1)/2 or N0=N/2. summed up, is N0=[N/2], where [] means rounding up. Leaf knot points can be calculated based on the total number of nodes in a fully binary tree.

Using equation 800/2 = 400, select C.

4. The stability of the ranking algorithm means that the key code of the same record before and after the relative position does not change, the following sort algorithm is not stable ()
A. Insert Sort
B. Bubble sort
C. Quick Sort
D. Merge sort

Explanation: Unstable: Quick Sort Hill Sort heap sorting Select sort

5. The following description of the process is incorrect ()
A. The process will automatically close all files it has opened when it exits
B. The process automatically closes its open network link when it exits
C. The process automatically destroys all threads that it creates when it exits
D. The process automatically destroys its open shared memory when it exits

Explanation: Since shared memory is shared, it is possible that several processes are in common possession, one process is over, and if the shared memory is destroyed then other processes will be destroyed; d

6. In a CPP file, define a global variable of type static, and the following is the correct description ()
A. The variable can only be used in the compilation module where the CPP resides
B. The value of the variable is immutable
C. The variable cannot be referenced in the member function of the class
D. The variable can only be a base type (such as int, char) cannot be a C + + type

Explanation: A is correct, static has a restricted scope to prevent it from being referenced by other files! D,static can be class type; BC is obviously wrong;

7. The following argument about overloaded functions is correct ()
A. Overloaded functions must have different return value types
B. The number of overloaded function parameters must be different
C. Overloaded functions must have a different list of formal parameters
D. Overloaded function names can be different

Explanation: C is simple


9. Which of the following cases does B not implicitly convert to a? ( )
A. Class B:public a{};
B. Class A:public b{};
C. Class b{operator A ();};
D. Class a{A (const b&);};

Explanation: According to the assignment compatibility principle, a subclass can be converted to a parent class to assign a value to the parent class object, but the reverse is incorrect, so B error

C is a type conversion function, d in the form of a constructor, C and D can be converted successfully!

10. Analyze the operation result of the following program: ()
#include <iostream.h>
Class CBase
{
Public
CBase () {cout<< "Constructing CBase class" <<endl;}
~cbase () {cout<< "destructing CBase class" <<endl;}
};
Class Csub:public CBase
{
Public
Csub () {cout<< "Constructing Csub class" <<ENDL;}
~csub () {cout<< "Destructing csub class" <<ENDL;}
};
void Main ()
{
Csub obj;
}
A. Constructing Csub Class
Constructing CBase Class
Destructing Csub Class
Destructing CBase Class
B. Constructing CBase Class
Constructing Csub Class
Destructing CBase Class
Destructing Csub Class
C. Constructing CBase Class
Constructing Csub Class
Destructing Csub Class
Destructing CBase Class
D. Constructing Csub Class
Constructing CBase Class
Destructing CBase Class
Destructing Csub Class

Explanation: Very simple to choose c


11. Two strings char* A, char* B, and the position order of output B in a.
void Output_postion (const char* A, const char* B);
such as: a = "ABDBCC" b = "abc"
b The order of position in A is
014
015
034
035

Explain:

#include <iostream> #include <string> #include <list> using namespace std;      void FindCore (String A, int aindex, string b, int bindex, list<int>& ans) {if (Bindex = = B.length ()) {for (List<int>::iterator iter = Ans.begin (); ITER! = Ans.end (); iter++) {COUT&LT;&L          T;*iter;      } cout<<endl;              } else {for (int i = Aindex; I < a.length (); i++) {if (a[i] = = B[bindex]) {Ans.push_back (i);//If equal, add the sequence number to the list L FindCore (A, i + 1, b, Bindex + 1, ans);   Recursive ans.pop_back ();//Backtracking}}} void find (const char* A, const char* b)      {string as = A;      string bs = b;  List<int> ans;//is used to hold the equivalent ordinal findcore (as, 0, BS, 0, ans);      } int main (int argc, char** argv) {char* a = "ABDBCC";      char* B = "abc";      Find (A, b);      return 0;   }


CSDN read some C 艹 pen questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.