C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 5)
5.
What is the output of the program
#include<stdio.h>
int main()
{
    struct emp
    {
        char name[20];
        int age;
        float sal;
    };
    struct emp e = {"Tiger"};
    printf("%d, %f\n", e.age, e.sal);
    return 0;
}
0, 0.000000
Garbage values
Error
None of above
Answer: Option
Explanation:
When an automatic structure is partially initialized remaining elements are initialized to 0(zero).
Discussion:
30 comments Page 2 of 3.

Asish said:   7 years ago
As per my knowledge, The array is getting garbage values and the other members are getting 0.

How? please explain this concept.

Shiwam pandey said:   1 decade ago
Is it not take default values when any structure defined partialy.

Element of structure should take default values.

Rizi said:   1 decade ago
What will be the o/p when we use the statement like struct emp e; instead of struct emp e={"tiger"}; ?

Arya said:   1 decade ago
If I remove the char initialization, the output will be changed why?

Can you please give me the answer please.

Bhuvana said:   1 decade ago
I can't understand where structure is partially initialized.

Could you please explain the concept please ?.

Sandeep said:   1 decade ago
In the question tiger is being assigned to the char array ony. how can you remove that initialization??

Prajakta said:   7 years ago
This is a local scope so 'why it does not take garbage value' can you please give me the answer?

Sakshi said:   1 decade ago
I can't get output I got error from this programme how to rectify please tell me?

Chaitali said:   1 decade ago
What o/p will I get if age is initialised and name & sal is not initialized?

Amulya said:   6 years ago
I'm not able to understand the program. Please anyone can explain it?
(1)


Post your comments here:

Your comments will be displayed after verification.