C Programming - Arrays - Discussion
Discussion Forum : Arrays - Find Output of Program (Q.No. 11)
11.
What will be the output of the program in Turbo-C ?
#include<stdio.h>
int main()
{
int arr[5], i=-1, z;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
Answer: Option
Explanation:
Since C is a compiler dependent language, it may give different outputs at different platforms. We have given the Turbo-C Compiler (under DOS) output.
Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better.
Discussion:
20 comments Page 2 of 2.
Gaurav said:
1 decade ago
How can answer be 0 1 2 3 4.. it seems wrong :-(
but it is right... i dont know how !!! wish someone could explain.
but it is right... i dont know how !!! wish someone could explain.
Srikanth said:
2 decades ago
The output for the above program
In Turbo C :
0, 1, 2, 3, 4,
In GCC :
1,2,3,4,5,
In Turbo C :
0, 1, 2, 3, 4,
In GCC :
1,2,3,4,5,
Mathan kumar said:
1 decade ago
Someone please explain program clearly (step-by-step).
Braj said:
1 decade ago
Its output is :.
1 2 3, 4, 5.
1 2 3, 4, 5.
Ankit said:
1 decade ago
How could array index be -1 ?
Venkateswarareddy said:
1 decade ago
What about return (0) ;
Sai Ram said:
8 years ago
Well said @Devi.
Shyamkumar said:
1 decade ago
Thank you devi.
Sam said:
1 decade ago
Thanx Devi...
Smriti said:
1 decade ago
Thanks devi.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers