C Programming - Typedef - Discussion
Discussion Forum : Typedef - Find Output of Program (Q.No. 5)
5.
What will be the output of the program?
#include<stdio.h>
typedef struct error {int warning, err, exception;} ERROR;
int main()
{
ERROR e;
e.err=1;
printf("%d\n", e.err);
return 0;
}
Discussion:
14 comments Page 1 of 2.
Manasa said:
6 years ago
Can we write the semicolon inside a closing curly braces? Please tell me.
Bharath kumar said:
7 years ago
@ALL.
As per my knowledge;
#include<stdio.h>
typedef struct error {int warning, err, exception;} ERROR;
int main()
{
ERROR e; /*typedef is used to rename. So (ERROR) as changed to (struct error) */
/* the above line code (ERROR e;) as changed to (struct error e;)*/
e.err=1;
printf("%d\n", e.err);
return 0;
}
As per my knowledge;
#include<stdio.h>
typedef struct error {int warning, err, exception;} ERROR;
int main()
{
ERROR e; /*typedef is used to rename. So (ERROR) as changed to (struct error) */
/* the above line code (ERROR e;) as changed to (struct error e;)*/
e.err=1;
printf("%d\n", e.err);
return 0;
}
Rohan said:
7 years ago
#include<stdio.h>
typedef struct error {int warning, err, exception;} ERROR;
/* typedef is used to rename. Here the name of the struct is changed from error to ERROR.............. */
int main()
{
ERROR e;
/* e is the object of ERROR structure ... */
e.err=1;
/* the value of err has been initialized with the help of object to the value 1 */
printf("%d\n", e.err);
/* 1 is the output............ */
return 0;
}
typedef struct error {int warning, err, exception;} ERROR;
/* typedef is used to rename. Here the name of the struct is changed from error to ERROR.............. */
int main()
{
ERROR e;
/* e is the object of ERROR structure ... */
e.err=1;
/* the value of err has been initialized with the help of object to the value 1 */
printf("%d\n", e.err);
/* 1 is the output............ */
return 0;
}
Soudip said:
10 years ago
In this structure variables act as int (all variables). So output is 1.
Karim said:
1 decade ago
Like, int itemp;
itemp =1;
typedef int myinteger;
myinteger imytemp; we cannot store value in to int or myinteger.
Same like structure.
itemp =1;
typedef int myinteger;
myinteger imytemp; we cannot store value in to int or myinteger.
Same like structure.
Hiren Raiyani said:
1 decade ago
Because its simple structure to give ERROR name and we initialize that so 1 is answer.
ElemenT said:
1 decade ago
@Everyone.
Guys don't confuse here with error and ERROR these two are different things error will act like struct keyword because you used typedef with it. ERROR is your actual structure for which your creating e as a reference so whenever you wrote e. Err = 1, it will store 1 at e. Err address and then it is just printing that value in printf.
I hope everyone got it.
Guys don't confuse here with error and ERROR these two are different things error will act like struct keyword because you used typedef with it. ERROR is your actual structure for which your creating e as a reference so whenever you wrote e. Err = 1, it will store 1 at e. Err address and then it is just printing that value in printf.
I hope everyone got it.
Mohan said:
1 decade ago
@Nagraj.
Generally we declare every variable separately. But it is not a necessary condition.
Generally we declare every variable separately. But it is not a necessary condition.
Rajkumar said:
1 decade ago
@Saravanan. C.
Here the variables are not declared as you have written.
Here the variables are not declared as you have written.
Shreyas said:
1 decade ago
@ Sathya
We are Typedefin the structure error to ERROR.
Therefore ERROR is acting like struct error.
ERROR e; is the same as struct error e;
We are Typedefin the structure error to ERROR.
Therefore ERROR is acting like struct error.
ERROR e; is the same as struct error e;
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers