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;
}
Answer: Option
Explanation:
When an automatic structure is partially initialized remaining elements are initialized to 0(zero).
Discussion:
30 comments Page 1 of 3.
Bhawna said:
5 years ago
If we initialize member of the structure like this : e.name = "tiger"; then it is giving garbage value of age. Why? Anyone explain it.
(1)
Silambarasan said:
6 years ago
The structure can be initialized inside the main function.
Amulya said:
6 years ago
I'm not able to understand the program. Please anyone can explain it?
(1)
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?
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.
How? please explain this concept.
Palanisuru said:
9 years ago
I am not understand this program, please explain in detail.
(1)
Sivaramireddy said:
9 years ago
I can't understand the program. Please explain me.
Bhushan patil said:
10 years ago
Is structure is define in main function?
Kani said:
1 decade ago
If anyone please explain the below concept, I can' t understand that:
If we use: printf("%s %d, %f\n", e.name, e.age, e.sal);
struct emp e = {"Tiger", 5, 1500.50}; // Full Initialization.
//Ouput: Tiger, 25, 1500.500000.
struct emp e = {"Tiger"}; // Partial Initialization.
//Ouput: Tiger, 0, 0.000000.
struct emp e ; // No Initialization.
//Ouput: GarbageValue, GarbageValue, GarbageValue!
If we use: printf("%s %d, %f\n", e.name, e.age, e.sal);
struct emp e = {"Tiger", 5, 1500.50}; // Full Initialization.
//Ouput: Tiger, 25, 1500.500000.
struct emp e = {"Tiger"}; // Partial Initialization.
//Ouput: Tiger, 0, 0.000000.
struct emp e ; // No Initialization.
//Ouput: GarbageValue, GarbageValue, GarbageValue!
(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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers