C language questions and answers

Source: Internet
Author: User
Tags file transfer protocol

A. volatile reminds that the variables defined after it can be changed at any time. Therefore, each time the compiled program needs to store or read this variable, it will directly

(1) volatile must be added to the variable modified in the interrupt service program for testing by other programs;
(2) A volatile label should be added for sharing tasks in a multi-task environment;
(3) The hardware register mapped to the memory usually needs volatile, because each read/write to it may have different meanings.

A.
(1) Application Layer: layer for communications between applications, such as simple Email transmission (SMTP), file transfer protocol (FTP, file transfer protocol), and network remote access protocol

Unlike TCP, UDP does not provide reliable IP protocol mechanisms, stream control, and error recovery functions. Because UDP is relatively simple, the UDP header contains a few bytes,

Tcp: provides stable transmission services with traffic control. The disadvantage is that the packet header is large and the redundancy is poor.
Udp: it does not provide stable services, with a small packet header and low overhead.


A.
Pre-compilation, also known as preprocessing, is the replacement of some code text. Process commands starting with #, such as copying the file code contained in # include, # replacing the definition of the define macro,

The main difference between struct in c and c ++ is that struct in c cannot contain member functions, while struct in c ++ can. In c ++, the main difference between struct and class lies in the default

* (Void (*) () 0x100000 )();
First, we need to forcibly convert 0x100000 into a function pointer, that is:
(Void (*) () 0x100000.
Then call it:
* (Void (*) () 0x100000 )();
You can see more intuitively with typedef:
Typedef void (*) () voidFuncPtr;
* (VoidFuncPtr) 0x100000 )();

The process is dead, but only a collection of resources. Real program execution is completed by threads. When the program starts, the operating system creates a main thread for you.
Each thread has its own stack.

Void GetMemory (char ** p, int num)
{
* P = (char *) malloc (num );
}
Int main ()
{
Char * str = NULL;
GetMemory (& str, 100 );
Strcpy (str, "hello ");
Free (str );
If (str! = NULL)
{
Strcpy (str, "world ");
}
Printf ("\ n str is % s", str); www.mscto.com
Getchar ();
}
What is the output result?
Output str is world.
Free is only the memory space pointed to by the released str, and its value still exists. So after free, there is a good habit of converting str = NULL.
At this time, the memory of the str pointing to the space has been recycled. If there is still a space allocation operation before the output statement, the storage space may be reassigned to other variables,
Although this program does have a big problem (as you have already mentioned above), it usually prints out world.
This is because memory management in a process is generally not completed by the operating system, but by the database function itself.
When you malloc a piece of memory, the management library applies for a piece of space from the operating system (which may be larger than the one you applied for), and then records some management information in the space.

Realize that this expression will overflow the integer number of a 16-bit machine-so the long integer sign L is used to tell the compiler that this constant is the long integer number.
If you use UL (representing an unsigned long integer) in your expression, you have a good starting point. Remember, the first impression is very important.
# Define SECONDS_PER_YEAR (60*60*24*365) UL

Test whether you know that it is legal to forcibly convert an integer number (typecast) into a pointer to access an absolute address. Implementation Method of this problem
The individual style varies. The typical code is as follows:
Int * ptr;
Ptr = (int *) 0x67a9;
* Ptr = 0xaa55;

# Define rWTCON (* (volatile unsigned *) 0x53000000)

{
Unsigned int a = 6;
Int B =-20;
(A + B> 6 )? Puts ("> 6"): puts ("<= 6 ");
}

(1) The keyword typedef is valid in the compilation phase. Because it is in the compilation phase, typedef has the type check function.
Define is a macro definition, which occurs in the preprocessing phase, that is, before compilation. It only performs simple and mechanical string replacement without any check.
(2) Typedef is used to define the type alias.
(3) # define has no scope restrictions. As long as it is a previously predefined macro, it can be used in future programs. Typedef has its own scope.

Or "<=. If it is written as if (x = 0.0), an error is returned. If (x> =-EPSINON) & (x <= EPSINON)

# Include <assert. h>
Void assert (int expression );

Char * GetMemory (void)
{
Char p [] = "hello world ";
Return p;
}

{
Char * str = NULL;
Str = GetMemory ();
Printf (str );
}


Return p;
The p [] array is the partial automatic variable in the function. After the function returns, the memory has been released. This is a common mistake made by many programmers,
Its root cause is that it does not understand the lifetime of a variable.

Quick Method:

{
Unsigned int c = 0;
For (c = 0; n; ++ c)
{
N & = (n-1); // clear the first digit
}
Return c;
}

{
// Create a table
Unsigned char BitsSetTable256 [0, 256] = {0 };

For (int I = 0; I <256; I ++)
{
BitsSetTable256 [I] = (I & 1) + BitsSetTable256 [I/2];
}

Unsigned char * p = (unsigned char *) & n;

BitsSetTable256 [p [1] +
BitsSetTable256 [p [2] +
BitsSetTable256 [p [3];

}

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.