Interview Question


Country: India




Comment hidden because of low score. Click to expand.
3
of 5 vote

#define square(X) X*X is a MACRO(google it)
and 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

- dabbcomputers March 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define square(X) X*X is a MACRO(google it)
and 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

- dabbcomputers March 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define square(X) X*X is a MACRO(google it)
and 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

- dabbcomputers March 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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);
}
}

- Anonymous October 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

answer will be 4 5 6 7 8 9 10

- Anonymous June 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

output will be 1 2 3 4

- sid January 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it will rather be 1 2 3 4 5 6 7 8 9 10

- sid` January 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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?

- Anonymous May 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

answer will be 4

- Anonymous June 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define square(v) v*v
Void main()
{
int p=3,s;
s=square(++3);
}
OUTPUT
25
Please explain the macro how the variable incremented....

- Subhashis February 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Macro just replaces the values so we get
++3 * ++3 (pre increment first increments and then assign)

- Kadambari April 12, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How the answer is 11
For2+3*2+3

- ArbiyA June 13, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

2+6+3

- Anonymous December 22, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

2+6+3

- Caesar December 22, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define SQUARE (X)X*X
Void main ()
{
printf ("not square =%d",SQUARE (10+2));
}

- Anonymous July 16, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Initially it simply replaces X as
10+2 * 10+2(By precedence)
20+10+2
32

- Kadambari April 12, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#define SQUARE(X) X*X
#define PR(X) printf("macro is %d\n",X)
main()
{
PR(100/SQUARE(2));
}

- Anonymous January 28, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

36

- Anonymous March 31, 2022 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#define square(x) x*x
main()
{
int i;
i=64/square(4);
printf("%d",i);
}

- Anonymous March 08, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

64

- Akshat August 07, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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))

- Ritik kumar March 06, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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))

- Ritik kumar March 06, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#define SQR(x)x*x
main()
{
int i;
i=64/SQR(4);
printf("%d",i);
}

- Anonymous November 04, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Chiranjeev September 10, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i=64/4*4
first do 64/4 = 16 then do 16*4 = 64

- Chiranjeev September 10, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define square(x) x*x void main(){ int x=6; printf("\n result is=%d",SQR(x-1));}

- Anonymous November 24, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

-1

- limon July 15, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<studio.h>
Int main()
{
Printf(“indiabix”);
Big main();
Return 0;
}

- Anonymous March 06, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int x = 0;
for (x=1; x<4; x++);
printf("x=%d\n", x);

- Anonymous January 25, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define sqare(a)a*a
Into main()
{
Print("%d,sqare(4+5));
Return 0;
}

- Anonymous February 20, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

#define squared(x) x*x

#define squared(x) (x*x)

#define squared (x) (x)*(x)

Double answer = 18/squared (2+1)

- Anonymous August 27, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#define SQUARE(X) X*X*X
int main()
{
printf("%d", SQUARE(10+2));
return 0;
}

- Anonymous November 19, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#define SQUARE(X) X*X*X
int main()
{
printf("%d", SQUARE(10+2));
return 0;
}

- Anonymous November 19, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# include <studio.h>
# define square (a) a*a
Int main

Print f ("%" , square (4+5));
Return 0;

- Anonymous March 16, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define square(x) x*x int main() { int x; x=36/square(6); printf("%dx) getchar(); return 0;} What would be the output

6

- Anonymous November 11, 2022 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More