This set of Arduino Multiple Choice Questions & Answers (MCQs) focuses on “Datatypes”.
1. What is the output of the code given below?
void setup() {
Serial.begin(9600);
}
void loop() {
String s=String(13,HEX);
Serial.println(s);
}
a) 13
b) A
c) B
d) D
View Answer
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; the number, and the base. Here the number 13 is given a base HEX which means it’s a hexadecimal number which makes it D.
2. What is the output of the code given below?
void setup() {
Serial.begin(9600);
}
void loop() {
String s=String(13,BIN);
Serial.println(s);
}
a) 13
b) 1101
c) 1001
d) null
View Answer
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; the number, and the base. Here the number 13 is given a base BIN which means it’s a binary number which makes it 1101.
3. How many bits of memory does the bool datatype occupy?
a) 2
b) 4
c) 6
d) 8
View Answer
Explanation: The bool datatype can only take 2 values; TRUE or FALSE. This takes a space of 8 bits or 1 byte. It’s mostly used in digital read or write operations to denote a 0V or 5V signal output or input. It can also be used for decision making.
4. What datatype should one use to represent 2147483610?
a) Int
b) Byte
c) Short
d) Long
View Answer
Explanation: Any number can be represented in the form of a whole number or a floating-point number. If it must be represented as a whole number, then there are many options depending upon the size of the number in question. Here the number 2146492440 should be represented using the long datatype since it has a range of -2147483648 to -2147483647.
5. How many bits of memory does the Short datatype take up?
a) 17
b) 15
c) 16
d) 14
View Answer
Explanation: Any number can be represented in the form of a whole number or a floating-point number. If it must be represented as a whole number, then there are many options depending upon the size of the number in question. Here the short datatype takes up 16 bits of memory. In other words, it can store numbers between -32768 to 32767.
6. What method does the int datatype use for storing negative numbers?
a) 1’s Complement
b) 2’s Complement
c) 3’s Complement
d) 4’s Complement
View Answer
Explanation: The int datatype stores 16 bits of data. The way it handles negative numbers is by a method called the 2’s complement wherein a sign bit is added to the binary equivalent of the number and then all the bits are inverted and then added by one.
7. How can you assign the binary number 101 to an integer variable?
a) Var = B101
b) Var = 101
c) Var = bin(101)
d) Var = Bin(101)
View Answer
Explanation: The concept used above is a binary formatter. If this letter is associated with the number during initialization of the variable, the number is converted from that base to the base 10 which is the decimal base. This binary formatter only works for numbers which have a length of 8 bits.
8. What will the output of the code be?
void setup() {
Serial.begin(9600);
}
void loop() {
int n=0x101;
Serial.println(n);
}
a) 200
b) 101
c) 119
d) 257
View Answer
Explanation: The concept used above is a hexadecimal formatter. If this letter is associated with the number during initialization of the variable, the number is converted from that base to the base 10 which is the decimal base. Thus, the output comes as 257.
9. What is the output of the following program?
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
View Answer
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.
10. How many errors are present in the program given below?
void setup() {
Serial.begin(9600);
pinMode(10,OUTPUT);
}
void loop() {
word x=1000;
}
a) 0
b) 1
c) 2
d) 3
View Answer
Explanation: The program given above is completely fine. It simply initializes a variable ‘x’ of the word datatype. The word datatype is a datatype that can store any unsigned whole number or integer ranging from 0 to 65535. It has a memory allocation of 16 bits.
Sanfoundry Global Education & Learning Series – Arduino.
To practice all areas of Arduino, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Electrical & Electronics Engineering Books
- Check Arduino Books
- Apply for Electrical & Electronics Engineering Internship
- Check Electrical Engineering Books
- Practice Electrical Engineering MCQs