C temp usage?

Mondo Technology Updated on 2024-02-09

How do I use temp in C? I would like to search for someone on this issueProbably misremembered the C++ template, because there is no word temp in the C keyword, if you don't believe it, you can check the details of the 32 keywords in the C language below:

The details of the keywords for C++ are as follows:

Only template has a character resemblance to temp.

In C++, the template keyword is used for declarationsProgram templates, which is specifically divided into:Function templateswithClass templates。The purpose of the program template is:Functions with similar aggregation functions and different data types are integrated to form a functional frameworkWhen a program template is executed, its actual function will be determined based on the parameters actually passed.

The declaration definition format for function templates and class templates is as follows:

1. Function template

Follow the order from simple to complex, and learn how to use template functions in C++ first.

For ease of understanding, the function template is defined using a simple summation operation. Since I have defined two types in the type form parameter table, the data types that are supported and manipulated in the C++ syntax can be passed as parameters, but it should be noted that the data width of parameter 2 must be greater than the data width of parameter 1 to ensure that the result of the operation does not overflow. If you want to perform operations on the same type of data in a function instance, you only need to define the type form parameter table as a type.

2. Class templates

Next, let's take a look at how C++ defines claims and uses class templates, as shown below

In this case, the class template declares a constructor and two ordinary member functions, one of which is returned using the second type in the formal argument table. The use of class templates, compared to normal classes, isThere is an additional use of angle brackets to specify specific data typesI believe that this way of writing must be familiar to people who are also learning j**a.

For more knowledge points about program templates in C++ programming, please explore them by yourself if you are interested, and we will not expand them here.

Related Pages

    Sqrt usage in C

    In C,the sqrt function is primarily providedSquare root calculationi.e.the reverse process of the squared operation.The function is declared in mathh ...

    Usage of while in C

    In C,the keyword while is used to proceedCycle operation,and the so called cycle isRepeat one or more commands。In fact,to understand what kind of stat...

    Usage of float in C

    In C,float is a basic type of data used to represent single precision floating point numbers,i.e.real numbers with decimal parts.Float data can be use...

    Usage of char in C

    In C,char is a data type that is used to represent characters.Here are the main uses of char in C .Character Variable Declaration char mychar Declare ...

    Can the temp folder of the C drive be deleted? This article answers the questions in detail

    In the Windows operating system,the Temp folder of the C drive is used to store temporary files.These files are generated while the application is run...