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 2 of 3.
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.
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.
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.
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.
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?
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?
"In function 'main':
Line 6: error: flexible array member not at end of struct"
why?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers