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 2 of 4.
Jorge said:
1 decade ago
It will be garbage value because the array is not initialized with any value at the beginning, the memory allocated by the array could contain random data from the ram.
Rupesh kumar jha said:
8 years ago
It depends upon compiler, the order of execution. In my system, linux (Ubuntu) GCC compiler it is giving output 1, 2, 3, 4, 5.
Vinay yadav said:
1 decade ago
In Turbo C, Compiler return garbage value if the a[0] is not initialized but in GCC it return 0 so output is different.
Gurjar said:
1 decade ago
In GCC compiler (Linux (Fedora 20)) it will give output
4195728, 1, 2, 3, 4,
Where 4195728 is garbage value.
4195728, 1, 2, 3, 4,
Where 4195728 is garbage value.
Manoj kumar said:
9 years ago
When an array is partially initialised. Remaining elements will be turn out to be zero. So, I feel option is c.
Maikal said:
1 decade ago
Rajendra singh & JORGE thanks for discuss this question, I WILL HOPE TO U FOR OTHER QUESTION EXPLANATION
Mayank said:
1 decade ago
++ has greater preference than assignment, rest you will understand automatically. Its better hint!
Vik said:
1 decade ago
In second for loop the condition not satisfied at last step so it prints garbage value.
Nandhinivijayan said:
1 decade ago
What is meant by garbage value? How it is identified? Any one explain me clearly ASAP?
Rishabh Manikpuri said:
8 years ago
Its answer is 1, 2, 3, 4, 5 and how does it showing garbage value in first place?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers