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;
}
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.
Hemant Pushkarna said:
2 years ago
The compiler shows error like that.
Here fr.c is a file name. it shows the first error as x is undeclared. So the answer of this question should be C, not D.
In function 'main':
fr.c:5:11: error: 'x' undeclared (first use in this function)
while(x=0;x<=255;x++)
^
fr.c:5:11: note: each undeclared identifier is reported only once for each function it appears in
fr.c:5:14: error: expected ')' before ';' token.
while(x=0;x<=255;x++)
Here fr.c is a file name. it shows the first error as x is undeclared. So the answer of this question should be C, not D.
In function 'main':
fr.c:5:11: error: 'x' undeclared (first use in this function)
while(x=0;x<=255;x++)
^
fr.c:5:11: note: each undeclared identifier is reported only once for each function it appears in
fr.c:5:14: error: expected ')' before ';' token.
while(x=0;x<=255;x++)
Rohan said:
7 years ago
@All.
char ch;
Step 1: a variable (ch) is declared as a character.
while(x=0;x<=255;x++)
printf("ASCII value of %d character %c\n", x, x);
Step 2: (i) x is undeclared and this error comes first when you run the computer...
(ii) syntax of while loop is wrong.
Instead it is like this
->> while(x<=255)
{
statement(s);
}
char ch;
Step 1: a variable (ch) is declared as a character.
while(x=0;x<=255;x++)
printf("ASCII value of %d character %c\n", x, x);
Step 2: (i) x is undeclared and this error comes first when you run the computer...
(ii) syntax of while loop is wrong.
Instead it is like this
->> while(x<=255)
{
statement(s);
}
Srinivas said:
8 years ago
Your answer is wrong this program.
The first error is x undeclared identifier.
The first error is x undeclared identifier.
(1)
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.
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.
Mage said:
9 years ago
Simply explain in a program.
Raj said:
9 years ago
Please make it as simple and understandable. What is the correct format of while loop?
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.
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.
Jay said:
10 years ago
How to know which error will come first?
Balaram sahu said:
1 decade ago
Syntax of while statement is wrong and also x is not declared in the programme.
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers