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.

Prasanna said:   1 decade ago
@Mr.Sivaraman.

struct emp means defining a structure with the name emp.

Structure is a collection of heterogeneous elements. Here the structure contains 3 variables name (it is an array), age and salary. Here e is the object to the structure.

Sivaraman said:   1 decade ago
What is struct emp?

Prameela said:   1 decade ago
I got an error when I compile it can anyone explain?

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

Sai said:   1 decade ago
String contains null character in it i.e "\0" is same as " ".

String takes the memory, it has given the address value of the null character stored.

For example if you have "tiger" which also have null character in it. i.e "tiger\0"

Any string at the end contains null.

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

Could you please explain the concept please ?.

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"}; ?

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

Keerthi said:   1 decade ago
Thankx sundar ji.

Krishna said:   1 decade ago
Why o/p is @ when use %c instead of %s in this program?


Post your comments here:

Your comments will be displayed after verification.