In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the C++ pointer parameter transmission essence and how to use the secondary pointer related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this C++ pointer parameter transmission essence and how to use the secondary pointer article will have a harvest, let's take a look.
Let's first look at two programs:
1:
Void test (char * p)
{
Printf ("[test1] [p]:% p.\ n", p)
Printf ("[test2] [p]:% s.\ n", p)
P = (char *) malloc (10)
Strcpy (p, "ABCDE")
Printf ("[test3] malloc after.\ n")
Printf ("[test4] [p]:% p.\ n", p)
Printf ("[test5] [p]:% s.\ n", p)
Free (p)
}
Int main ()
{
Char b [6] = "abcde"
Char * a = b
Printf ("[main1] [a]:% p.\ n", a)
Printf ("[main2] [a]:% s.\ n", a)
Test (a)
Printf ("[main3] [a]:% p.\ n", a)
Printf ("[main4] [a]:% s.\ n", a)
Return 0
}
Output: note: (the pde value of the test function has changed, but the value of an of the main function has not changed)
Main1] [a]: 0xbfeaaef6.
[main2] [a]: abcde.
[test1] [p]: 0xbfeaaef6.
[test2] [p]: abcde.
[test3] after malloc.
[test4] [p]: 0x8a52008.
[test5] [p]: ABCDE.
[main3] [a]: 0xbfeaaef6.
[main4] [a]: abcde.
2:
Void test (char * * p)
{
Printf ("[test1] [p]:% p.\ n", p)
Printf ("[test2] [* p]:% p.\ n", * p)
* p = (char *) malloc (10)
Strcpy (* p, "ABCDE")
Printf ("[test3] malloc after.\ n")
Printf ("[test4] [p]:% p.\ n", p)
Printf ("[test5] [* p]:% p.\ n", * p)
Printf ("[test6] [* p]:% s.\ n", * p)
Free (* p)
}
Int main ()
{
Char b [6] = "abcde"
Char * a = b
Printf ("[main1] [a]:% p.\ n", a)
Printf ("[main2] [a]:% s.\ n", a)
Test & a)
Printf ("[main3] [a]:% p.\ n", a)
Printf ("[main4] [a]:% s.\ n", a)
Return 0
}
Output: note: (the pde value of the test function has changed, and the value of an of the main function has also changed)
[main1] [a]: 0xbfaca776.
[main2] [a]: abcde.
[test1] [p]: 0xbfaca770.
[test2] [* p]: 0xbfaca776.
[test3] after malloc.
[test4] [p]: 0xbfaca770.
[test5] [* p]: 0x9132008.
[test6] [* p]: ABCDE.
[main3] [a]: 0x9132008.
[main4] [a]: ABCDE.
This is the end of the article on "the essence of C++ pointer parameter transmission and how to use the secondary pointer". Thank you for reading! I believe that everyone has a certain understanding of the "C++ pointer parameter transmission essence and how to use the secondary pointer" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.