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

write a simple calculator c program to perform addition, subtraction, mul and div.

0 Answers   United Healthcare, Virtusa,


#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }

2 Answers  


What are the files which are automatically opened when a C file is executed?

1 Answers  


Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)

7 Answers   Microsoft,


main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } } a. 512, 256, 128, 64, 32 b. 256, 128, 64, 32, 16 c. 128, 64, 32, 16, 8 d. 64, 32, 16, 8, 4

2 Answers   HCL,






Write a function to find the depth of a binary tree.

13 Answers   Adobe, Amazon, EFI, Imagination Technologies,


Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }

1 Answers  


Print an integer using only putchar. Try doing it without using extra storage.

2 Answers  


main() { int i =0;j=0; if(i && j++) printf("%d..%d",i++,j); printf("%d..%d,i,j); }

1 Answers  


What are segment and offset addresses?

2 Answers   Infosys,


main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }

1 Answers  


main() { char *p; p="%d\n"; p++; p++; printf(p-2,300); }

1 Answers  


Categories