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 > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of what is the concept of C++ default parameters, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this C++ default parameter concept article. Let's take a look.
I. the concept of default parameters
The default parameter is to specify a default value for the function's parameters when you declare or define the function. When calling the function, the default value is used if no argument is specified, otherwise the specified argument is used.
# includeusing namespace std;void TestFunc (int a = 0) / / Parameter default {cout capacity = 0; ps- > size = 0;} void StackPush (struct Stack* ps, int x) {if (ps- > size = = ps- > capacity) {/ / ps- > capacity * = 2Tracer ps- > capacity = 0? 4: ps- > capacity * 2 / / you must write a ternary} void StackInitCpp1 (struct Stack* ps, int defaultCP) {ps- > a = (int*) malloc (sizeof (int) * defaultCP); ps- > capacity = 0; ps- > size = defaultCP;} void StackInitCpp2 (struct Stack* ps, int defaultCP = 4) / / ok {ps- > a = (int*) malloc (sizeof (int) * defaultCP); ps- > capacity = 0 Ps- > size = defaultCP;} int main () {/ / suppose you know clearly that you need at least 100 pieces of data to st1 struct Stack st1; StackInitCpp1 (& st1, 100); / / suppose you don't know how much data is needed in st2-you want to turn on struct Stack st2; StackInitCpp2 (& st1); / / default return 0 Default parameter classification all default parameters void TestFunc (int a = 10, int b = 20, int c = 30) {cout
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.