Error in the following prog?????

Status
Not open for further replies.

thecall

Junior Member level 2
Joined
Mar 4, 2007
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,448
Is there any error in this program.

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()

{
clrscr();
char arr[8]="Rhombus";
int i;
for(i=0;i<=7;i++)
printf("\n%d",*arr);
arr++;


}
 

Yes!

First error,
You can not call any functions and then declare variables.
You must declare all variables before you execute any code.

{
clrscr(); /* ERROR */

char arr[8]="Rhombus";

should be:

{
char arr[8]="Rhombus";

clrscr();

Second error,

arr is a constant pointer, you cant increment it.

should be *(arr+i)

Third error,

The program will print the value of 'R' eight times, if you want to increment arr, you have to have brackets.

for(i=0;i<=7;i++)
{
printf("\n%d",*arr);
arr++;
}

but that wont work anyway, it should be,

for(i = 0; i <= 7; i++) {
printf("\n%d",*(arr+i));
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…