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 2 of 2.
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);
}
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++)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers