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 is the difference between if else and switchstatement
Linked lists -- can you tell me how to check whether a linked list is circular?
What is the process to generate random numbers in c programming language?
What does %c mean in c?
Explain void pointer?
How does pointer work in c?
write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3
How do I copy files?
What is string function c?
Does c have class?
How can I remove the trailing spaces from a string?
How can you return multiple values from a function?
What is meant by keywords in c?
What is variable declaration and definition in c?
which is conditional construct a) if statement b) switch statement c) while/for d) goto