In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the interview questions in C language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the C language interview questions?"
1. Describe the difference between the two statements:
Char * p = "hello"
Char p [] = "hello"
Answer:
(1), char * p means that the pointer p is a pointer to a character constant, pointing to a constant area, so you can't modify the contents of memory. If, for example, p [0] = 'Franks, then the compiler will report an error.
(2) the p in char p [] is the first address of an array of characters assigned in a readable and writable memory, and the contents of the array can be changed.
2. What happens when a function returns a pointer to a local variable (such as the following example)?
Void GetString ()
{
Char p [] = "hello world"
Return p
}
Answer:
(1) the memory space occupied by the local array is allocated by the compiler in the stack. When the function returns, the occupied stack space will be unstacked by the code added by the compiler. At this time, all the data stored in the stack becomes invalid data. Therefore, the pointer returned will point to an invalid stack space. Any access to what it points to through this pointer is invalid (the data may have been changed by subsequent stack operations) and dangerous (the data written through this pointer may wash away the valid data of subsequent stack operations).
3. Volatil keyword is used to modify variables in c language. Please explain its usage and common usage.
Answer:
(1) the role of volatile is to tell the compiler that the variable it modifies may be changed at any time, so every time the compiled program uses the value of the variable, it will read the data from the address of the variable instead of getting it from the register (in other words, a variable defined as volatile means that the variable may be changed unexpectedly, so that the compiler will not assume the value of the variable. To be precise, the optimizer must carefully reread the value of the variable every time it uses it, rather than using a backup saved in the register. As an example, it is more error-prone:
Int square (volatile int * p)
{
Return (* p) * (* p)
}
In this case, you want to calculate the square of the value of memory pointed to by pointer p, but if you use volatile here, you may not be able to achieve the result you want. We can write it in another way and make it more straightforward:
Int square (volatile int * p)
{
Int a,b
Axiomaticp
Bachelorette
Return a * b
}
For the correct way of writing, you can refer to this:
Int square (volatile int * p)
{
Int a
Axiomaticp
Return a * a
}
Summary: the negative use of this keyword, that is, do not want to change, you can use the keyword const usage, about the use of const, readers can see how much they have mastered?
(2) its common usage:
The hardware register of a parallel device (e. G. status register).
A non-automatic variable that is accessed in an interrupt service subroutine.
A variable shared by several tasks in a multithreaded application.
At this point, I believe you have a deeper understanding of "what are the interview questions in C language?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.