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;
}
1, 2, 3, 4, 5,
Garbage value, 1, 2, 3, 4,
0, 1, 2, 3, 4,
2, 3, 4, 5, 6,
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 4 of 4.

Rupinderjit said:   1 decade ago
Many thanks jorge for the explanation

Shelly said:   5 years ago
Wonderfully explained. Thanks @Dada.

Nishitha said:   1 decade ago
But why it will give garbage value?

Shravan said:   6 years ago
Can anyone please explain this?

Abhimanyu said:   1 decade ago
How it will give garbege value?

Karthick said:   1 decade ago
@rajendra singh
Thanks a lot..

Dnyanu said:   8 years ago
Yes, Agree @Manoj.

Seenu said:   5 years ago
Explain please.


Post your comments here:

Your comments will be displayed after verification.