Arduino Questions and Answers – PROGMEM Utility

This set of Arduino Questions and Answers for Aptitude test focuses on “PROGMEM Utility”.

1. In which memory does the Arduino save data in when the PROGMEM Utility is invoked?
a) EEPROM
b) SRAM
c) Flash
d) DRAM
View Answer

Answer: c
Explanation: When the PROGMEM Utility is invoked, data being saved is diverted to the flash memory instead of the SRAM. This utility is a variable modifier, which means it can change the variable policy whenever invoked.

2. Which header file contains the PROGMEM Utility?
a) The avr/pgmspace.h header file
b) The pmspace.h header file
c) The avr/pspace.h header file
d) The avr/progmem.h header file
View Answer

Answer: a
Explanation: The PROGMEM Utility is contained within the avr/pgmspace.h header file and this file is to be invoked whenever a programmer needs to use the PROGMEM Utility for his or her program. However, while using the data stored in the Flash memory one also needs to use certain functions defined within the header file to retrieve the data.

3. What type of variables does the PROGMEM Utility work on?
a) Globally Defined or static
b) Defined inside a function and non-static
c) Defined inside a for-loop and non-static
d) Defined inside a while-loop and non-static
View Answer

Answer: a
Explanation: The PROGMEM Utility can only be used for variables which have “public” access to the entire program and conversely can be accessed by anyone, or is a static variable, which means they need to be defined outside a function and be static or non-static, or if they are defined within any function, they need to be static.
advertisement
advertisement

4. Can the PROGMEM Utility work on non-static variables?
a) Yes
b) No
View Answer

Answer: a
Explanation: The PROGMEM Utility can be used with non-static variables provided they are defined outside any function, i.e. they are defined globally. Conversely if one needs to work on a variable that is not defined globally then they would need to convert that variable into a static variable in order to use the PROGMEM Utility.

5. Can PROGMEM be used on arrays?
a) Yes
b) No
View Answer

Answer: a
Explanation: When the PROGMEM Utility is invoked, data being saved is diverted to the flash memory instead of the SRAM. This utility is a variable modifier so it can be used on any kind of data structures allowed by the language.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. What is the equivalent macro for the PROGMEM Utility when dealing with sending data that is to be printed, into the Flash memory?
a) A() Macro
b) C() Macro
c) F() Macro
d) N() Macro
View Answer

Answer: c
Explanation: The F() macro is used for sending data, which is usually in the form of strings that are declared within the Serial.print() function which means they are not to be stored anywhere in the program but are to be printed onto the serial monitor, to the Flash Memory before it is printed.

7. Given below are four lines of boilerplate code. Which ones are faulty?

advertisement
const dataType variableName[] PROGMEM = {};
const PROGMEM dataType variableName[] = {};
const dataType PROGMEM variableName[] = {};
dataType PROGMEM const variableName[] = {};

a) Lines 1 and 3
b) Lines 3 and 4
c) Lines 1 and 2
d) Lines 3 and 2
View Answer

Answer: b
Explanation: The PROGMEM Utility can only be used for variables which have “public” access to the entire program and conversely can be accessed by anyone, or is a static variable, which means they need to be defined outside a function and be static or non-static. This means that there is a certain degree of syntactical freedom that the programmer is vested with when using the PROGMEM Utility since it is a variable modifier.
advertisement

8. In which versions of the Arduino IDE can the PROGMEM Utility be used without declaration in the Arduino code?
a) Any Arduino IDE version above 2.0
b) Any Arduino IDE version above 1.0
c) Any Arduino IDE version below 1.0
d) Any Arduino IDE version above 3.1
View Answer

Answer: b
Explanation: PROGMEM is part of the avr/pgmspace.h library. It is imported automatically in the more recent versions of the Arduino IDE. However, if one is using an IDE version below 1.0, then the header must be included first at the top of the code.

9. What is the purpose of the boilerplate code given below?

strcpy_P(buffer, (char *)pgm_read_word(&(StringVariable)));

a) To copy data from the SRAM
b) To copy data from the EEPROM
c) To copy data from the Flash Memory
d) To copy data to the EEPROM
View Answer

Answer: c
Explanation: The boilerplate code given, does the job of retrieving the data for a particular variable, for use in the program. This function gives “READ” access to the programmer into the Flash Memory for retrieving any variable data saved in the Flash Memory by the PROGMEM Utility.

10. What is the use of the boilerplate code given below?

someByte = pgm_read_word ( &( someData[x][y] ) );

a) Reading Strings from Flash Memory
b) Reading Integers from Flash Memory
c) Reading files from Flash Memory
d) Reading special characters from Flash Memory
View Answer

Answer: b
Explanation: The boilerplate code given, does the job of retrieving the integer data for a particular variable, for use in the program. This function gives “READ” access to the programmer into the Flash Memory for retrieving any variable data saved in the Flash Memory by the PROGMEM Utility.

Sanfoundry Global Education & Learning Series – Arduino.

To practice all areas of Arduino for Aptitude test, 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.