Programming Languages C Objective
Mar 07, 2013

What will be output of following c code?

#include<stdio.h>

int main(){

    int i=1;

    for(i=0;i=-1;i=1) {

         printf("%d ",i);

         if(i!=1) break;

       }

    return 0;

}

Choose the correct answer:
B) 1
C) -1
D) 2
Detailed Explanation

Initial value of variable i is 1.

First iteration:

For loop initial value: i = 0

For loop condition: i = -1 . Since -1 is non- zero number. So loop condition true. Hence printf function will print value of variable i i.e. -1

Since variable i is not equal to 1. So, if condition is true. Due to break keyword program control will come out of the for loop.

 

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback