Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the atoi function in C++

Shulou Source: shulou.com Published: 2022-06-02 09:53:57 09月16日 Update

How to understand the atoi function in C++, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

I. atoi function

In stdlib.h, the atoi function can be used to convert char strings to int integers.

The syntax is as follows:

/ * * description: convert a char type to an integer * * Parameter: * [in] string: string type * * return value: return the integer * / int atoi (char * string) corresponding to the char type II. Atoi function practice / / @ Author: ape programming / / @ Blog (personal blog address): www.codersrc.com//@File:C language tutorial-C atoi + atoi function wchar_t conversion / / @ Time:2021/08/10 08:00//@Motto: do not accumulate steps to reach thousands of miles, do not accumulate small streams can not become rivers and seas, program life needs to unremittingly accumulate! / * / # include "stdafx.h" # include # include "windows.h" # pragma warning (disable: 4996) int _ tmain (int argc _ TCHAR* argv []) {printf ("atoi function calculation result% d\ n", atoi ("13456")) Printf ("atoi function calculation% d\ n", atoi ("0"); printf ("atoi function calculation% d\ n", atoi ("789")); printf ("atoi function calculation% d\ n", atoi ("123.123")); / / default to integer printf ("atoi function calculation% d\ n", atoi ("- 9")); system ("pause") Return 0;}

Output:

The calculation result of atoi function is 13456

The calculation result of atoi function is 0

Calculation result of atoi function 789

The result of atoi function calculation is 123

Calculation result of atoi function-9

Please press any key to continue. . .

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Functions results integers types characters strings help Cards clarity brilliance perseverance non-accumulation of steps thousands of miles individuals life content blogs parameters addresses actual combat Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information OPPO Reno macOS Xiaomi