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.

Krishna said:   1 decade ago
If we not give size of name than error will come
"In function 'main':
Line 6: error: flexible array member not at end of struct"
why?

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

Keerthi said:   1 decade ago
Thankx sundar ji.

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

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

Jemi said:   1 decade ago
#include<stdio.h>
int main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e = {" ",24,67888};
printf("%d, %f\n", e.name, e.sal);
return 0;
}

Output is :-1086310732, 67888.000000

Why name is in -ve, it should also be 0.

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.

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

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

Sivaraman said:   1 decade ago
What is struct emp?


Post your comments here:

Your comments will be displayed after verification.