what is the output of following question?
void main()
{
int i=0,a[3];
a[i]=i++;
printf("%d",a[i]
}
Answers were Sorted based on User's Feedback
my opinion or wat i think is that ,
a[i]=i++; is given so...
here i++ is a post increment operation , so first it will assign the value to a[0]=0 , so a[0] will have 0 , and in next line a[i] is given in printf , so the value a[1] should get printed that will be garbage value.......
thank u
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / sha
Vignesh, you are right about the post incerement operation.
The a[i]=a[0] which will be assigned 0 but the printf will
print 0 as output because its printing the a[0] and not a
[1].
| Is This Answer Correct ? | 0 Yes | 0 No |
A garbage value
Explanaiton:-since we have post increment operator applied on i. It's value gets incremented in next statement, so
a[i]=i++ means a[0]= 0
so a[0] is assigned value 0;
and now i becomes 1;
In next statement value of a[i] is to be printed which means value of a[1], which is not initialised. So value printed is a
garbage value.
Remarks
1. An uninitialised variable holds a garbage value.
2. Post increment operator increments value in next line.
| Is This Answer Correct ? | 0 Yes | 0 No |
a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);
What is infinite loop?
How does free() know how many bytes to free?
main() { int l=6; switch(l) { default:l=l+2; case 4:l=4; case 5:l++; break; } printf("%d",l); }
what is compiler
What does %c do in c?
write a program that finds the factorial of a number using recursion?
If errno contains a nonzero number, is there an error?
What is include directive in c?
How do I get a null pointer in my programs?
What is a wrapper function in c?
please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com