C Programming - Arrays - Discussion
Discussion Forum : Arrays - Find Output of Program (Q.No. 7)
7.
What will be the output of the program in Turb C (under DOS)?
#include<stdio.h>
int main()
{
int arr[5], i=0;
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 TurboC Compiler (Windows) output.
Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better.
Discussion:
38 comments Page 3 of 4.
Rohit said:
8 years ago
How the first value is a gargbage. I think output should be 1, 2, 3, 4, 5.
Ecc29 said:
1 decade ago
Can anyone explain the output difference between Turbo C and GCC please?
Kyaw win thu said:
1 decade ago
I want to know the definition of garbage value with example please.
Kalyan said:
1 decade ago
It will gives 1, 2, 3, 4, 5 how it will gives garbage value?
Zishu said:
1 decade ago
Why this program doesn't give the first option as output?
Thanvi said:
1 decade ago
Can any one explain the difference between a++, ++a ?
Pooja dev said:
1 decade ago
But [] has higher precedence over = and ++.
Mohan said:
6 years ago
I think operation takes from right to left.
Shreyash said:
10 years ago
It will be option C i.e 1.
0, 1, 2, 3, 4.
0, 1, 2, 3, 4.
Abhishek said:
1 decade ago
In DevC++.
Output are:
2358963,1,2,3,4
Output are:
2358963,1,2,3,4
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers