C++/C face question

Source: Internet
Author: User

(1)

Bitwise operations apply only to character and integer variables, and to their variants, which do not apply to other data types;

(2)

In general, when you open a Web page, you need to enter the URL in the browser, so you need to find the IP address of the resource through the URL, so that the request can be sent to the corresponding machine, in this process requires the DNS (domain Name System, domainname, it is the Internet as the domain name and IP A distributed database that maps addresses to each other, making it easier for users to access the Internet without remembering IP data strings that can be read directly by the machine. The process of obtaining the IP address of the host name through the hostname is called the "Domain name resolution" protocol; HTTP is the transport protocol used to transfer hypertext from a WEB server to a local browser. The browser interacts with the server over HTTP. HTTP is an application-layer protocol that transmits HTTP requests over TCP at the transport layer. Telnet is the standard protocol and primary method for Internet remote login services. It provides users with the ability to perform remote host work on the local computer. The general use method is to log in to a remote host through a terminal, so it is not available in the browser when the Web page is opened.

(3) The method that belongs to the structure scatter function is

The common methods of constructing hash functions are Direct addressing method , digital analysis method, square method, folding method, residue remainder method and random number method .

1) Direct addressing method : Take a keyword or a keyword of a linear function value is a hash address. For example, H (key) =a*key+b, where A and B are constants.

2) Digital Analysis Method : If the keyword is based on R (for example, 10 decimal number), and the hash list may appear in advance of the keywords are known beforehand, the preferred keyword of several digits to form a hash address.

3) The square takes the middle method : Takes the key word square after several as the hash address.

4) Folding method : The keyword is divided into several parts of the same number of bits, and then take these parts of the overlay and as a hash address.
5) In addition to the remainder of the method : Take the keyword by a number less than or equal to the hash list length m of the remainder as a hash address (f (key) = key mod p (p≤m), M is the hash table length).

6) Random number method: Select a random function to take the random function value of the keyword as its hash address.

(4)

A copy constructor is a special constructor that is called by the compiler to complete the construction and initialization of other objects based on the same class. The name of the copy constructor must be the same as the class name, the formal parameter of the function is a reference variable of this type, and must be a reference;

(5) The static member function exists independently of the object, cannot implement polymorphism, and the static member function does not have the this pointer, cannot find the virtual function table, so the static member function cannot be designed as virtual function;

(6) The inline property of a function is determined at compile time and is a static behavior. The nature of virtual is determined at run time and is dynamic behavior.

(7) Can not use the return value to distinguish the overloaded function, judging by: parameter type, the number of parameters.

(8) The elements of the known set A and set B are stored with a single linked list without a head node, and the function difference () is used to solve the difference between set a and set B, and the results are saved in the single linked list of set a. For example, if the collection a={5,10,20,15,25,30}, set b={5,15,35,25}, completes the calculation a={10,20,30}.

struct node
{
int value;
Node* Next;
};

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include "difference.h"
void difference (node** LA, node* LB)
{
Node *pa, *PB, *PR, *q;//pr links for deleting nodes
PR = NULL;
PA = *la;
while (PA)//Refer to the values in the linked list LA, and then compare to the elements in LB
{
PB = LB;
while (pb&&pb->value! = pa->value)//lb linked list does not go to the end and ...
PA = pa->next;
if (PB)//Find an identical value, here with non-empty
{
if (!PR)//PR is used to point to the previous node of the same element, this is the head node
*la = pa->next;
Else//la's head node did not find the same value in lb, which is not the head node
Pr->next = pa->next;//
Q = pa->next;//Delete the same node
PA = pa->next;
Free (q);
}
ELSE//LB traversed and did not find the same,
{
PR = PA;
PA = pa->next;
}
}
}

(9) Static local variables are stored in the global zone of the process;

(10). There is a variable. There is a variable. There is a variable int int a=0a=0, two threads at the same time +1 operation, each thread plus 100 operations do not lock the last time, do not lock the last time, unlocked the last value of a?

Multithreading (multithreading) is the implementation of concurrent execution of multiple threads on software or hardware. In this scenario, the +1 operation is performed as follows: Remove the variable A, perform a +1 operation on the variable a, and put the result back. If none of the +1 operations in two threads were interrupted and all +1 operations took effect, then a 200 +1 operation was performed on a, in which case A's value becomes 200.

Because these two threads are not locked when they perform a +1 operation on a, it is possible that some +1 operations will be lost. The process is as follows:

1) Thread 1 reads the value of variable a (read into the register) is 0.

2) thread 2 reads the value of variable A, at which point it reads a value of 0.

3) Thread 1 performs a +1 operation on a and puts it back, at which point A has a value of 1.

4) Thread 2 also performs a +1 operation on a and puts it back, since the value of a in the register in thread 2 is 0, +1 is performed after the action is executed, and a value of 1 is returned.

In this case, thread 1 performs a +1 operation on a is lost. Therefore, the maximum value of a is 200 after execution finishes.

C++/C face question

Related Article

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.