C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 9)
9.
Point out the correct statements are correct about the program below?
#include<stdio.h>
int main()
{
    char ch;
    while(x=0;x<=255;x++)
        printf("ASCII value of %d character %c\n", x, x);
    return 0;
}
The code generates an infinite loop
The code prints all ASCII values and its characters
Error: x undeclared identifier
Error: while statement missing
Answer: Option
Explanation:

There are 2 errors in this program.
1. "Undefined symbol x" error. Here x is not defined in the program.
2. Here while() statement syntax error.

Discussion:
12 comments Page 1 of 2.

Abid khan said:   1 decade ago
While statement work properly.

But x is not declared so while statement missing.

Vinoth said:   1 decade ago
Khan you understand in while loop only condition is checked.

Eg:while(x>5).

Praveen said:   1 decade ago
Ambiguous Answers, X is undeclared and while statement is wrong.
Depends on Compiler to show which error first.
How it parses the program.

In option both x undeclared and while error should be as one answer.

Balaram sahu said:   1 decade ago
Syntax of while statement is wrong and also x is not declared in the programme.

Jay said:   10 years ago
How to know which error will come first?

Guddu said:   9 years ago
It showing error as,

sh-4.3$ gcc -o main *.c
main.c: In function 'main':
main.c:5:11: error: 'x' undeclared (first use in this function)
while(x=0;x<=255;x++)
^ main.c:5:11: note: each undeclared identifier is reported only once for each function it appears in,
main.c:5:14: error: expected ')' before ';' token
while(x=0;x<=255;x++)

So I think the answer should be C only.

Raj said:   9 years ago
Please make it as simple and understandable. What is the correct format of while loop?

Mage said:   9 years ago
Simply explain in a program.

Mashkur Khadmi said:   8 years ago
err.c: In function \'main\':
err.c:5:11: error: \'x\' undeclared (first use in this function)
while(x=0;x<=255;x++)
^
err.c:5:11: note: each undeclared identifier is reported only once for each function it appears in
err.c:5:14: error: expected \')\' before \';\' token
while(x=0;x<=255;x++)
=======================================================

First, the compiler will check during compilation, after while loop it will check for ' x ' which is undeclared.

It will generate error, And next will be the While loop syntax error.

Srinivas said:   8 years ago
Your answer is wrong this program.

The first error is x undeclared identifier.
(1)


Post your comments here:

Your comments will be displayed after verification.