C/C++ code snippet 1 (macro):
1 |
|
C/C++ code snippet 2 (function):
1 2 3 4 |
|
An integer array of 5 elements is declared and initialized in
main()
as
int arr[5]={1,2,3,4,5};
.
The macro and function of the code snippets above are declared and defined globally.
From
main()
, the macro and the function are called with the argument
arr
as follows,
1 2 |
|
What's the
absolute difference
between the values stored in
m
and
f
, i.e., what's the value of
?
Details and Assumptions:
m
and
f
are
int
variables.
sizeof()
is an inbuilt C/C++ function which returns the number of bytes occupied by an object.
main()
is the function block which is called first when the code is compiled and executed.
Assume that the code is being executed in a 32-bit compiler on a 32-bit machine, which means that an
int
or
int*
variable takes 4 bytes of memory, i.e., we have
sizeof(int)
=
sizeof(int*)
=4.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Just Run It! ( Solution )
Explanation(in brief):
The Macro snippet always return the number of indecies of an array so m= 5 according to the problem.
The Function snippet always return 1 since:
return sizeof(x)/sizeof(*x);
so f= 1 ∣ m − f ∣ = 4