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;
}
0
1
2
Error
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
14 comments Page 2 of 2.

Soudip said:   10 years ago
In this structure variables act as int (all variables). So output is 1.

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

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

Manasa said:   6 years ago
Can we write the semicolon inside a closing curly braces? Please tell me.


Post your comments here:

Your comments will be displayed after verification.