What is the output of the following program? [code] void setup() { Serial.begin(9600); } void loop() { String s=String(5.231, 1);

What is the output of the following program?
Code:
void setup() {
    Serial.begin(9600);
}
void loop() {
    String s=String(5.231, 1);
    Serial.println(s);
}
A. 5
B. 5.2
C. 5.23
D. 5.231
 
Answer: B
Explanation: The program above makes use of the String() function to convert the given number into a string. The String() function takes a maximum of 2 arguments; in this case, the number and the decimal point limit. The decimal point limit dictates the number of decimal points till which the String() function should convert the number to a String. The rest is omitted.
 

Tìm kiếm

Back
Top