Saturday, 18 February 2017

C Programming Questions with Explanation

Q:: What will be the output for following loop :->

for(putchar('c');putchar('a');putchar('r'))
{
                putchar('t');
}

 (a)error             (B)cartrt
(C)catrat            (D)catratratrat...

As per for loop execute

for(1. Initialization;2.Condition Check; 3. Iteration Variable change)

Now as per given question
1. Initialization is given by putchar('c)
2. Condition Check by putchar('a')
3. Iteration by putchar('r')

In for loop statement putchar('t') is there

Also sequence is 
1. Initialization only once putchar('c')
2. Condition check putchar('a')
3. Statement putchar('t')
4. Iteration putchar('r')
2. putchar('a')
3. putchar('t')
4. putchar('r')
2. putchar('a')
3. putchar('t')
.
.
.
and so on so result will catratratrat.... Infinite times

No comments:

Post a Comment