In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to analyze void, const and return in C language keywords. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Return
First of all, let's figure out how to allocate memory in c language.
Then we look at a piece of code:
# pragma warning (disable:4996) # includechar* string () {char arr [] = "hello world"; return arr;} int main () {char* s = string (); printf ("% s", s); return 0;}
When running to the printf function, s still points to "hello world", but why does it end up printed out as garbled?
Let's first look at the allocation of memory in the stack area.
When the string function is finished, the stack frame it creates is destroyed, but the destruction here is not to zero its data, but to set it to override data.
But why did it end up garbled again?
That's because printf is also a function and has to create space, so the stack frames created by string are overwritten.
So we explained the reason for the garbled code perfectly.
Void I. A general interface that can be used as a function
Example:
Application: char* s = (char*) malloc (sizeof (char))
Reason:
Pointers of type void can be accepted by pointers of any type or pointers of any type.
2. Void cannot modify variables
Reason: the compiler does not know how much space is allocated to variables
III. Void modifier function returns a value
Placeholder, telling the user not to return a value
If not, the default is the return value of type int.
Const
Const-modified variables cannot be modified directly, but can be passed through pointers
But const still has its meaning.
1. Let the compiler tell us in advance that the variables that should not be modified have been modified.
two。 Let the children's shoes that look at the source code know that they cannot be modified here.
On how to analyze the C language keywords in void, const and return to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.