Embedded C problem

Source: Internet
Author: User
Tags first string

What is the role of 1.const?
First, limit a read-only variable (not a constant). such as const double PI = 3.14 Second, qualifying function parameters, such as void functions (const char *P)//function can only read cannot change the value of P
2. What is the meaning of the keyword volatile?
Volatile affects compiler compilation results, indicating that volatile variables are at any time likely to change, with volatile variables related to the operation, do not compile optimization, to avoid errors
3. The embedded system always wants the user to perform bit operation on the variable or register. Given an integer variable A, write two segments of code, the first one sets a bit 3, and the second clears the bit 3 of a. In the above two operations, keep the other bits intact.
1, the bit3 of A is assigned a value of 1 a |= (0x01<< 3),//a or equal to 1 left 3 bits, so that the rest of the bit unchanged, BIT3 is assigned to 1 2, the bit3 of a to clear a &= ~ (0x01<< 3);// A and equals (1 is reversed after left 3), so that the other bits are not changed, BIT3 is cleared
4. What types of data are customized with typedef?
1, used to define a type of alias, so that it can be used to define the variable continuously, rather than a simple macro substitution, such as: typedef char* PCHAR;  PCHAR PA, PB; 2, in the C era, after the definition of a struct, and then use the struct keyword to be used to define variables, this will be more troublesome, and using typedef to define, you can not write the struct keyword, such as: typedef struct      tagpoint {int x;  int y;  }point; Point P1; Of course, C + + does not have to do this, because C + + does not need to add the struct keyword 3 when using structs, and typedef to define platform-independent types. For example, you have a cross-platform project, you need to use a double-precision floating-point type, and on some platforms may not have this implementation, or implementation of different, this time you can be based on different platforms to define your own type 4, to simplify the complex definition, the most commonly used is to define a function pointer alias, so , in general, TypeDef is not "invented" another new type, but equivalent to a type of alias, for ease of use.
5.sizeof is an operator, and the result of the operation is the size of the type (number of bytes in memory);

Strlen () is a function that returns a value of the length of a string.
6. Write a short, char, unsigned char representation range?
1 bytes = 8 bits
In a 32-bit system, a char type is typically 8 bits, so the data can be stored in the range -128~127, while the unsigned char is 0~255, and the character type stores data that is used to represent characters, such as Ascⅱ or Unicode. The range of signed char is 127 to 127.short-32767 ~ + 32768 (2 Bytes)
7. Write a strcpy () function? 10 min
void strcpy (char *strdest, char *strsrc)
{

while ((*strdest++ = * strsrc++)! = "\");
} (4 points)
Another type of:
In order to realize the chain operation, return the destination address, add 3 points!
char * strcpy (char *strdest, const char *STRSRC)
{

ASSERT ((strdest! = null) && (STRSRC! = null));
char *address = strdest;

while ((*strdest++ = * strsrc++)! =?);
return address;
}
8. There are several ways to allocate memory, their differences, each example.
1) allocation from a static storage area. Memory is allocated at the time of program compilation, and the entire running period of the program is present in this block. For example, global variables, static variables. 2) Create on the stack. When executing a function, the storage units of local variables within the function can be created on the stack, which are automatically freed when the function is executed at the end. The stack memory allocation operation is built into the instruction set of the processor. 3) allocation from the heap, also known as dynamic memory allocation. When the program is running, it uses malloc or new to request any amount of memory, and the programmer is responsible for freeing the memory with free or delete. The lifetime of dynamic memory is determined by programmers and is very flexible to use, but the problem is the most.
9.const usage, as well as declaring the const variable different from the macro.
There are four ways to use const: parameters, return values, functions, and const-modified variables to restrict variables to read-only, and the value of the variable is not allowed to be changed. Using const can also save memory space.
Define: Defines a macro that is processed during precompilation; only simple character substitution, no type detection const: Define constants in the program, compile-time processing, constant modifiers, define variables as constants.
What is the use of 10.static? (at least two kinds of instructions)
1) Limit the scope of the variable 2) set the storage domain of the variable
11. What is the difference between a queue and a stack?
Stack is a linear table that restricts insertions and deletions to only one end of a table. A queue is a linear table that qualifies only one end of a table to be inserted and deleted at the other. From the point of view of "data structure", they are all linear structures, that is, the relationship between data elements is the same. But they are completely different data types. In addition to their respective basic set of operations, the main difference is the "qualification" of the insert and delete operations. Stack and queue are two kinds of linear data structures widely used in program design, they are characterized by the particularity of basic operation, the stack must be operated by "last in first out" rule, and the queue must be operated by "FIFO" rule. Compared with linear tables, their insertions and deletions are more constrained and limited, so they are also called the finite linear table structure.
12. Write the Bubbling Sort code:

13.c instruction and use:650) this.width=650; "title=" 1.png "src=" http://s3.51cto.com/wyfs02/M01/59/DB/ Wkiol1ttghbdl0mkaaflmbtprcs187.jpg "alt=" Wkiol1ttghbdl0mkaaflmbtprcs187.jpg "/>

The difference betweensizeof and strlen :

sizeof sizeof Yes operator ' memory bytes

is an operator, the result of which is the size of the type
is a function that returns a value of length of a string

Strlen : strlen is just the work of a counter that starts scanning from somewhere in memory until it touches the first string Terminator ' + ' and then returns the counter value.

write out the range of short, char,unsigned char?

650) this.width=650; "title=" 2.png "src=" Http://s3.51cto.com/wyfs02/M00/59/DB/wKioL1TtgrKCtI_fAALNSRJIT7k011.jpg " alt= "Wkiol1ttgrkcti_faalnsrjit7k011.jpg"/>

16. (Single chip microcomputer) STM32 IO eight configuration mode:

650) this.width=650; "title=" 3.png "src=" Http://s3.51cto.com/wyfs02/M00/59/DF/wKiom1TtgiThIPNJAADRARKWR4s438.jpg " alt= "Wkiom1ttgithipnjaadrarkwr4s438.jpg"/>

Application of the 17.C pointer:

1. Some high-level statements:

1) int *f (void);

F is a function, and the return value type is a pointer to an integral type.

2) int (*f) (void);

F is a function pointer, which points to the function return value type is an integer value.

3) int * (*F) (void);

F is a function pointer, and the function return value it points to is an integer pointer that can only be accessed indirectly to get an integer value.

4) int *f[];

F is an array whose element type is a pointer to an integral type (an array of pointers).

5) int (*f[]) (void);

F is an array, the type of the array element is a function pointer, and the function return value it points to is an integer value.

6) int * (*f[]) (void);

F is an array, the type of the array element is a function pointer, and the function return value that it points to is a pointer to an integral type.

2. When the function name is used, it is always converted by the compiler to a functional pointer.

18. What to consider when selecting resistors (hardware)?
The choice resistor is required to consider the resistance of the power resistance to allow the maximum current to be loaded at both ends of the voltage allowed and so on.

19. (Single-chip microcomputer) The microcontroller is not running after power, first to check what?
1) power supply, check the MCU pin voltage value is correct
2) to see if the crystal oscillator is working properly, you can use the oscilloscope to view
3) Check the minimum system has the wrong connection, circuit breaker and other problems, with a multimeter.

(Linux) briefly describes the initialization process for embedded Linux systems.

The embedded Linux system starts by running bootloader, then booting the kernel by bootloader, the kernel checks and initializes the hardware device, loads the device's driver module, installs the root file system, and the kernel launches a process called init (2 points). After the Init run completes and other necessary subsequent processes are started, the system begins to run and the boot process ends. When the init process starts, it needs to read the Inittab configuration file, which determines the operating characteristics of INIT when the system starts and shuts down.



This article is from the "Sun Catcher" blog, please make sure to keep this source http://976455580.blog.51cto.com/8852101/1615255

Embedded C problem

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.