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 1 of 2.

Varad said:   1 decade ago
any one help me for this problem plzz...

Saravanan.C said:   1 decade ago
typedef struct error
{
int warning;
int err;
int exception;
}ERROR;

This is how this normally looks....

Here a structure named error is typedefed as ERROR(means in place of struct error it can be said as ERROR)...
then e is a structure..
e.err is accessing a member in the structure... thats it.... is it correct......?

Sathya said:   1 decade ago
In c how can u create an object like ERROR e; ? Is it correct?

Instead of using e.err , why cant we simply use ERROR.err?

Nagaraj said:   1 decade ago
Hey in the structure, how can we declare like that ?

Every variablemust be declared separately, am I right?

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;

Rajkumar said:   1 decade ago
@Saravanan. C.

Here the variables are not declared as you have written.

Mohan said:   1 decade ago
@Nagraj.

Generally we declare every variable separately. But it is not a necessary condition.

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.

Hiren Raiyani said:   1 decade ago
Because its simple structure to give ERROR name and we initialize that so 1 is answer.

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.


Post your comments here:

Your comments will be displayed after verification.