Arduino Questions and Answers – Datatypes

This set of Arduino Multiple Choice Questions & Answers (MCQs) focuses on “Datatypes”.

1. What is the output of the code given below?

  1. void setup() {
  2.      Serial.begin(9600);
  3. }
  4. void loop() {
  5.     String s=String(13,HEX);
  6.     Serial.println(s);
  7. }

a) 13
b) A
c) B
d) D
View Answer

Answer: d
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.
advertisement
advertisement

2. What is the output of the code given below?

  1. void setup() {
  2.     Serial.begin(9600);
  3. }
  4. void loop() {
  5.     String s=String(13,BIN);
  6.     Serial.println(s);
  7. }

a) 13
b) 1101
c) 1001
d) null
View Answer

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; 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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

3. How many bits of memory does the bool datatype occupy?
a) 2
b) 4
c) 6
d) 8
View Answer

Answer: d
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.
advertisement

4. What datatype should one use to represent 2147483610?
a) Int
b) Byte
c) Short
d) Long
View Answer

Answer: d
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

Answer: c
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.
advertisement

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

Answer: b
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

Answer: a
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?

  1. void setup() {
  2.     Serial.begin(9600);
  3. }
  4. void loop() {
  5.     int n=0x101;
  6.     Serial.println(n);
  7. }

a) 200
b) 101
c) 119
d) 257
View Answer

Answer: d
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?

  1. void setup() {
  2.     Serial.begin(9600);
  3. }
  4. void loop() {
  5.     String s=String(5.231, 1);
  6.     Serial.println(s);
  7. }

a) 5
b) 5.2
c) 5.23
d) 5.231
View Answer

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.

10. How many errors are present in the program given below?

  1. void setup() {
  2.     Serial.begin(9600);
  3.     pinMode(10,OUTPUT);
  4. }
  5. void loop() {
  6.     word x=1000;
  7. }

a) 0
b) 1
c) 2
d) 3
View Answer

Answer: a
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.