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

Recommended Answers

All 7 Replies

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

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
D)#define INTEREST 5, LOAD 5000

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");
      }
  }
commented: Do your own damn homework! -2

Why don't you answer your questions with what you think is the right answer and why?

commented: Yes. +27

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.