Interview Question
Country: India
What is the output of the following code?
#include<stdio.h>
void main ( )
{
int s=0;
while (s++<10)
{
if(s<4&&s<9)
continue;
printf(“ %d/t”,s);
}
}
int x = 0; for (x=1; x<4; x++); printf("x=%d\n", x);
What will be printed when the sample code above is executed?
#define square(v) v*v
Void main()
{
int p=3,s;
s=square(++3);
}
OUTPUT
25
Please explain the macro how the variable incremented....
#include <stdio.h>
#define SQUARE(X) X*X
#define PR(X) printf("macro is %d\n",X)
main()
{
PR(100/SQUARE(2));
}
Preprocessor replaces square(6) by 6*6 and the expression becomes x = 36/6*6 and value of x is calculated as 36. Note that the macro will also fail for expressions "x = square(6-2)" If we want correct behavior from macro square(x), we should declare the macro as
#define square(x) ((x)*(x))
Preprocessor replaces square(6) by 6*6 and the expression becomes x = 36/6*6 and value of x is calculated as 36. Note that the macro will also fail for expressions "x = square(6-2)" If we want correct behavior from macro square(x), we should declare the macro as
#define square(x) ((x)*(x))
i=64/4*4
(it means first evaluate 64/4 which is equal to 16 then do 16*4 which is equal to 64)
therefore answer is 64
#define square(X) X*X is a MACRO(google it)
- dabbcomputers March 30, 2012and compiler replace the macro with defination
so code become
sq= X*X in our code X is 2+3 so it become 2+3*2+3
so ans=11