void main()
{
int a[]={1,2,3,4,5},i;
for(i=0;i<5;i++)
printf("%d",a++);
getch();
}
Answer Posted / vikas thakur
The answer is error.
The reason is that we can't increment a constant(the
variable int a[] ). The expression int a[] is the address
where the system had placed your array and it will remain
to stay at that address until the program terminates. you
can't increment an address but you can increment a pointer.
.....the correct program would be....
void main()(
int a[]={1,2,3,4,5},i;
for(i=0;i<5;i++)
printf("%d",a[i]);
getch();
}
....in another way.....
void main()(
int a[]={1,2,3,4,5},i;
int *p;
p = a;
for(i=0;i<5;i++)
printf("%d",*(p++));
getch();
}
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?
Explain how do you sort filenames in a directory?
How can a program be made to print the line number where an error occurs?
How do you construct an increment statement or decrement statement in C?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
What are the storage classes in C?
What is the difference between c and python?
What is #error and use of it?
Is that possible to store 32768 in an int data type variable?
What is difference between far and near pointers?
What is the difference between array and structure in c?
Are there any problems with performing mathematical operations on different variable types?
given post order,in order construct the corresponding binary tree
What is call by reference in functions?
What is use of bit field?