typedef struct error{int warning, error, exception;}error;

main()

{

error g1;

g1.error =1;

printf("%d",g1.error);

}



typedef struct error{int warning, error, exception;}error; main() { ..

Answer / susie

Answer :

1

Explanation

The three usages of name errors can be distinguishable
by the compiler at any instance, so valid (they are in
different namespaces).

Typedef struct error{int warning, error, exception;}error;

This error can be used only by preceding the error by struct
kayword as in:

struct error someError;

typedef struct error{int warning, error, exception;}error;

This can be used only after . (dot) or -> (arrow) operator
preceded by the variable name as in :

g1.error =1;

printf("%d",g1.error);

typedef struct error{int warning, error, exception;}error;

This can be used to define variables without using the
preceding struct keyword as in:

error g1;

Since the compiler can perfectly distinguish between these
three usages, it is perfectly legal and valid.

Note

This code is given here to just explain the concept
behind. In real programming don’t use such overloading of
names. It reduces the readability of the code. Possible
doesn’t mean that we should use it!

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Code Interview Questions

#include<stdio.h> main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } }

1 Answers  


int aaa() {printf(“Hi”);} int bbb(){printf(“hello”);} iny ccc(){printf(“bye”);} main() { int ( * ptr[3]) (); ptr[0] = aaa; ptr[1] = bbb; ptr[2] =ccc; ptr[2](); }

1 Answers  


main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }

1 Answers  


what is variable length argument list?

2 Answers  


main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }

2 Answers  






main() { extern int i; i=20; printf("%d",i); }

1 Answers   Value Labs,


How can i find first 5 natural Numbers without using any loop in c language????????

2 Answers   Microsoft,


How do you write a program which produces its own source code as its output?

7 Answers  


How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.

1 Answers  


Is the following code legal? struct a { int x; struct a b; }

1 Answers  


main() { int i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) { printf(“%s\n”,x); x++; } }

2 Answers  


union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0

1 Answers   HCL,


Categories