number of iterations in the following loop

``````main()
{ int x=5, y=10, z=9
for (;x<=5;)
{y++;z--;
x=x+1/2;
if(z==0) z=y;}}``````

Edited by Nick Evan: Added code-tags...

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Ancient Dragon

Number of iterations? Infinite. Why? because 1/2 = 0 (integer division) so the value of x will never change.

What will be the output of the following code segment (assuming sizeof (int) returns 4)

``````int i= 0x1<<sizeof (int)*8-1;
printf("\n%x", i);
i=i>>sizeof(int)*8-1;
printf("%d",i);``````

Edited by WaltP: Added CODE Tags -- again

Which one is the valid statement in C?
A)#define half(x) ((x/2.0)
B)#define STREQ(s1,s2) (strcmp((s1),(s2))==0);
C)#define MAX=5

Choose the correct option to find maximum of the three interger variables.
A) (a>b)?((a>c)?a:c):((b>c)?b:c)
B)(a>b)?((b>c)?b:c):((a>c)?a:c)
C)(a>b)?((c>b)?a:c):((a>c)?a:c)
D) None

What is the effect of the following code?

``````main()
{
int option=4;
switch(option/2)
{
case 1: printf("EAST");
case 2: printf("WEST");
case 3: printf("NORTH");
case 4: printf("SOUTH");
}
}``````

Edited by WaltP: And again...

Yes.

What is the effect of the following code?
main()
{
int option=4;
switch(option/2)
{
case 1: printf("EAST");
case 2: printf("WEST");
case 3: printf("NORTH");
case 4: printf("SOUTH");
}
}

Hint: there are no break statements between the cases.