What would be the output of the program? [code] int pin=11; void setup() { pinMode(pin,OUTPUT); int a=0; Serial.begin(9600); } void

What would be the output of the program?
Code:
int pin=11;
void setup() {
    pinMode(pin,OUTPUT);
    int a=0;
    Serial.begin(9600);
}
void loop() {
    digitalWrite(pin,HIGH);
    Serial.println(a);
}
A. 0
B. null
C. error
D. 1
 
Answer: B
Explanation: The code above is wrong since the variable ‘a’ which is declared within the scope of the setup() function is invoked for printing in the subsequent loop() function. This is a violation of the scope policies hence the program will give an error.
 

Tìm kiếm

Back
Top