“atol” function:
In C++, the predefined function “atol” is used to convert a string value into a long integer value; it passes a string literal or character array as an argument and it converts the received value into a long integer value; it takes only one parameter as an argument.
- If the argument value contains nonconvertible contents combined with the integer value then the values will be ignored while converting.
- In same way, the function will return “0” when the values can’t be able to convert into double data type.
Syntax:
Syntax for “atol” function is as follows:
long int atol (const char* n);
In the above statement,
- “long int” represents the return type of the function.
- “atol” represents the name of the function.
- “const char*” represents the data type of the passing argument.
- “n” is a string variable which is required to be converted.
Example:
The example for the “atol” function is as follows:
//change the string literal to a long type value
long n = atol ("123456 hello");
In the above line, the string literal “123456 hello” is passed as an argument to “atol” and it returns the converted value that is “123456”; here the “atol” function ignores the whitespace and the nonconvertible value “hello”.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
STARTING OUT WITH C++FROM CONTROL STRU
- Which statement will not result in a syntax error? string initial = 'J' ; string initial = "J";arrow_forwardWhich string method does the following: To determine if a certain character is a letter or a number.arrow_forwardLet's imagine that the term huge is a string. Create a statement that lowercases the string it refers to before assigning it to the small variable.arrow_forward
- Let s1 be a variable containing the string "utica". Which of the following expressions changes the value in s1 to "Utica"? Select one: a. 'U'+s1[1:] b. s1='U'+s1[1:] c. s1[0]='U' d. s1='U'+s1arrow_forwardWrite two scnr.nextInt statements to get input values into birthMonth and birthYear. Then write a statement to output the month, a slash, and the year. End with newline.Ex: If the input is 1 2000, the output is:1/2000arrow_forwardWhich statement is a legal statement? Group of answer choices A.string & bad1 = “hello”; B.string & bad2 = str + “ ”; C.string & sub = str.substr( 0, 4); D.string && bad1 = “hello”; E.All of the abovearrow_forward
- If the strWord variable contains the string “spring”, which of the following statements assigns the letter r to the strLetter variable? a. strLetter = strWord.Substring(2) b. strLetter = strWord(2) c. strLetter = strWord(2, 1) d. All of the above.arrow_forwardThe following condition evaluates to True when the string stored in the strLetter variable is lowercase letter; otherwise, it evaluates to False. Please complete the code. If strLetter Like ....... Thenarrow_forwardWhich of the following expressions will produce the shown string?arrow_forward
- Write a statement to output the bottom plot. yVals2 = 0.5 * (abs(cos(2*pi*xVals)) - cos(2*pi*xVals));arrow_forwardWrite a program that prompts the user to enter a string and displays the characters at even positions.arrow_forwardWhich string method converts all the characters of a string to upper case?a) capitalize b) capwords c) uppercase d) upperarrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage