Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top