निम्नलिखित Arduino कोड का आउटपुट क्या होगा?
What will be the output of the following Arduino code ?
void main() {
int k = 0;
double d = 10.21;
printf(“%lu”, sizeof(k + d));
}
void loop() {}
A)
B)
C)
D)
Explanation:
The given Arduino code is:
void main() {
int k = 0;
double d = 10.21;
printf("%lu", sizeof(k + d));
}
void loop() {}
Explanation:
-
int k = 0; double d = 10.21;
:k
is an integer, andd
is a double.
-
sizeof(k + d)
:- In the expression
k + d
,k
is promoted todouble
because arithmetic operations between integers and doubles result in adouble
type. - The result of
k + d
will be a double.
- In the expression
-
sizeof(k + d)
:- The
sizeof
operator returns the size of the resulting type of the expression. - Since the result of
k + d
is adouble
, and the size of adouble
is 8 bytes on most systems,sizeof(k + d)
will return 8.
- The
Correct Answer:
(B) 8