Q::What will be the output::
void main()
{
static char ch=1;
while (ch++)
{
printf("℅d",ch);
}
}
(A) error
(B) It will run infinite time
(C) Prints 2,3,4...127 ,-128-127-126...-1
(D) Prints 2,3,4...127, -128-127-126...-1,0
Answer:: (D)
Explanation::
Firstly ch= 1 so , control enter the while loop and ch is incremented by 1
and ch =2 gets printed
going on this way the value of ch will become 127 and again it will be incremented by 1 which will make it -127 which is again true in C Language then -126,-125... -1,0 also get printed . Before printing value of ch is always incremented by 1.
No comments:
Post a Comment