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


Please Help Members By Posting Answers For Below Questions

What is the difference between if else and switchstatement

1313


Linked lists -- can you tell me how to check whether a linked list is circular?

646


What is the process to generate random numbers in c programming language?

610


What does %c mean in c?

654


Explain void pointer?

592






How does pointer work in c?

621


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

1645


How do I copy files?

623


What is string function c?

568


Does c have class?

614


How can I remove the trailing spaces from a string?

617


How can you return multiple values from a function?

634


What is meant by keywords in c?

618


What is variable declaration and definition in c?

503


which is conditional construct a) if statement b) switch statement c) while/for d) goto

740